[Tutor] pickling codecs

Dinesh B Vadhia dineshbvadhia at hotmail.com
Wed Sep 8 14:24:47 CEST 2010


I use codecs to retain consistent unicode/utf-8 encoding and decoding for reading/writing to files.  Should the codecs be applied when using the pickle/unpickle function?  For example, the standard syntax is:

# pickle object
f = open(object, 'wb')
pickle.dump(object, f, 2)
 
# unpickle object
f = open(object, 'rb')
object= pickle.load(f)
 
or should it be:

# pickle object
f = codecs.open(object, 'wb', 'utf-8')
pickle.dump(object, f, 2)


# unpickle object
f = codecs.open(object, 'rb', 'utf-8')
object= pickle.load(f)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100908/6e866af4/attachment.html>


More information about the Tutor mailing list