Q. Identify the error in the following code.


1. f = open("/tmp/workfile', 'r+')
2. f.write('0123456789abcdef')
3. f.write('xyz8466')
4. f.close()
5. f.seek (0)
6. f.read()

Answer :-

The lines 5 and 6 will raise the error as no operation can take place in a closed file-file is closed at line4. Since the file is opened in read as well write mode, we just need to bring line 4 at the end of the code.

Post a Comment

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

Previous Post Next Post