Pickling arbitrary character strings on Windows
Nicholas K. Sauter
nksauter at lbl.gov
Tue Mar 6 12:23:57 EST 2001
It would be good to be able to pickle strings containing arbitrary ASCII
characters, for example to encode data at the C level. But on Windows
it is impossible to do a binary unpickle of a string that has an
embedded ASCII 26 (octal 032). This example code tells the whole story:
from pickle import dump,load
def myfunc(i):
pro = "I_am_a_" +chr(i)+ "string"
f = open('try.bin','w'); dump(pro,f,1); f.close()
g = open('try.bin','r'); str = g.readline()# i=10 is a linefeed
(that's OK)
print "read string",i,len(str),"characters"
if __name__=="__main__":
for i in xrange(256):
myfunc(i)
Some obvious workarounds are to use formatted output (dump(pro,f,0)) or
to use Unix instead of Windows. But is there any way to implement a
practical binary string pickle on Windows?
Nick Sauter, LBNL
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nksauter.vcf
Type: text/x-vcard
Size: 301 bytes
Desc: Card for Nicholas K. Sauter
URL: <http://mail.python.org/pipermail/python-list/attachments/20010306/6fdc1b7c/attachment.vcf>
More information about the Python-list
mailing list