Q. Following code is written to update a record in a file opened with following code:


import pickle
fin = open("Stu.dat', 'rb')

try:
    while True:
        _____ = fin.tell() # Line 1: store file-pointer position before reading the record
        stu = pickle.load(fin))
        if stu['Marks'] in [92, 93, 94]:
            stu[ 'Marks'] += 3 #changes made in the record
            fin._____ (_____) # Line 2 :place the file-pointer at the exact location of the record
            pickle.dump(stu, fin) # now write the updated record on the exact location
except:
:



Fill in the blanks in Lines 1 and 2 to complete the code.


Answer :-

Line 1: position = fin.tell() # can use any identifier in place of position

Line 2: fin.seek (position)

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post