Hello I´m trying using the next piece of code:
import pickle object = Object() filehandler = open(filename, 'w') pickle.dump(object, filehandler)
I would like to know what should be the extension of the file 'filename'. Thank you!
File created by pickle, a Python module that allows objects to be serialized to files on disk and deserialized back into the program at runtime; saves a byte stream that represents the objects; more often uses the . P extension rather than ". pickle."
Python pickle module is used for serializing and de-serializing a Python object structure. Any object in Python can be pickled so that it can be saved on disk. What pickle does is that it “serializes” the object first before writing it to file. Pickling is a way to convert a python object (list, dict, etc.)
The pickle module can store things such as data types such as booleans, strings, and byte arrays, lists, dictionaries, functions, and more.
You could use any filename
, but as an FYI it's common to use ".p" (for obvious reasons).
pickle.dump( favorite_color, open( "save.p", "wb" ) )
Read: UsingPickle
One more thing you should pay attention to:
you should used binary mode with operation of pickling files. So 'w' should be 'wb'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With