pickling and __safe_for_unpickling__
Laura Falk
laura at wolf2.eecs.umich.edu
Fri May 17 11:18:25 EDT 2002
I'm on my first python program and ran into a python error while
unpickling my items from a socket. In reading the docs, I've found
that an attribute needs to be set __safe_for_unpickling__ but when
I try to set it but get an erro "object has read-only attributes". I
set the attribute as follows (I'm probably setting it incorrectly)
class fileinfo:
def __init__(self,file,cat,dir,name,dir_file,time,mode):
self.file = file
self.cat = cat
self.dir = dir
self.name = name
self.dir_file = dir_file
self.time = time
self.mode = mode
self.__safe_for_unpickling__=1
The docs also mention copy_reg so I removed the last line in the above
and then placed the following outside the class and then used the
following:
copy_reg.constructor(fileinfo)
When I ran the program again, I got the following:
Traceback (most recent call last):
File "./server.py", line 21, in ?
accepter.unpackinfo(data)
File "./accepter.py", line 16, in unpackinfo
p._is_string_secure=1
TypeError: object has read-only attributes
I'm come to the conclusion that I'm thoroughly confused as to how I
need to tell python that my data is safe to unpickle.
Can anyone give me advice/help with this problem? I'm very new to
python (I'm still in my first week since I started reading the book
and programming with python.)
Thanks very much for any help!!
--Laura Falk
More information about the Python-list
mailing list