__reduce__(1) vs __reduce__(2)
Kirill Simonov
xi at gamma.dn.ua
Tue Apr 18 16:27:22 EDT 2006
Could someone explain why __reduce__(2) works for files while
__reduce__(1) doesn't?
>>> f = file('/etc/passwd')
>>> f.__reduce__(1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/copy_reg.py", line 69, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects
>>> f.__reduce__(2)
(<function __newobj__ at 0xb7e6317c>, (<type 'file'>,), None, None, None)
What is a correct procedure of getting state and restoring Python objects?
--
xi
More information about the Python-list
mailing list