开发者

Python: saving objects and using pickle. extension of filename

开发者 https://www.devze.com 2023-01-31 23:05 出处:网络
Hello I´m trying using the next piece of code: import pickle object = Object() filehandler = open(filename, \'w\')

Hello I´m trying using the next piece of code:

import pickle 
object = Object() 
filehandler = open(filename, 'w') 
pickle.dump(object, filehandler) 

I wou开发者_C百科ld like to know what should be the extension of the file 'filename'. Thank you!


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'.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消