#!/bin/python3 import os def GetPos(): pos = int(input ("Enter a position 0-9, 10 to quit > ")) return pos; def DoARead(): task = input("Enter r to read, w to write, or d to dump the file > ") task = task[0].lower() return task fd = os.open("seekerFile.txt",os.O_RDWR) values = 'abcdefghij' len = os.lseek(fd,0,os.SEEK_END); if (len < 10): print ("\tCreating the file") os.lseek(fd,0,os.SEEK_SET) os.write(fd,values.encode()) len = os.lseek(fd,0,os.SEEK_END); pos = GetPos() while pos < 10: os.lseek(fd, pos, os.SEEK_SET) action = DoARead() if action == 'r': value = os.read(fd,1) print("The value at position", pos , " is " , value.decode()) elif action == 'w' : value = input("Enter a character to write >"); os.write(fd, value[0].encode()) elif action == 'd': print ("Dumping the file") os.lseek(fd, 0, os.SEEK_SET) text = os.read(fd,len) print (text.decode()) print(" ") pos = GetPos()