Peterstone
Peterstone

Reputation: 7459

Python: saving objects and using pickle. extension of filename

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!

Upvotes: 24

Views: 24987

Answers (2)

Krishan Gupta
Krishan Gupta

Reputation: 3716

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

Upvotes: 28

user225312
user225312

Reputation: 131767

Depends on what you want to do with the file.

filename should be sufficient.

And don't use object as an identifier. It shadows the builtin object.

Upvotes: 9

Related Questions