Python etching error: io.UsupportedOperation: read

I am trying to learn how to pickle and save an object in python. However, when I use the sample code below, I get the following error: io.UnsupportedOperation: read , which returns to favorite_color = pickle.load(f_myfile) . I can not find a good explanation for this particular error. What am I doing wrong and how to fix it?

 import pickle # or import cPickle as pickle # Create dictionary, list, etc. favorite_color = { "lion": "yellow", "kitty": "red" } # Write to file f_myfile = open('myfile.pickle', 'wb') pickle.dump(favorite_color, f_myfile) f_myfile.close() # Read from file f_myfile = open('myfile.pickle', 'wb') favorite_color = pickle.load(f_myfile) # variables come out in the order you put them in f_myfile.close() 
+6
source share
1 answer

Edit:

 # Read from file f_myfile = open('myfile.pickle', 'wb') 

to:

 f_myfile = open('myfile.pickle', 'rb') 

and you can see the recorder that you pickled.

+16
source

Source: https://habr.com/ru/post/954434/


All Articles