Q. Identify the error in the following code:


1. import pickle
2. data = ['one', 2, [3, 4, 5]]
3. with open('data2.dat', 'rb') as f:
4.     pickle.dump(data, f)

Answer :-

The file is opened in read mode and dump() function tries to write onto file, hence the error.

So the line 3 should be changed to L

with open('data2.dat', 'wb') as f:

Post a Comment

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

Previous Post Next Post