Python: saving objects and using pickle. extension of filename

Peterstone picture Peterstone · Dec 25, 2010 · Viewed 20.4k times · Source

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!

Answer

Krishan Gupta picture Krishan Gupta · May 25, 2014

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