[ python-Bugs-1474680 ] pickling files works with protocol=2.
SourceForge.net
noreply at sourceforge.net
Sat Apr 22 18:20:51 CEST 2006
Bugs item #1474680, was opened at 2006-04-22 19:20
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1474680&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Kirill Simonov (kirill_simonov)
Assigned to: Nobody/Anonymous (nobody)
Summary: pickling files works with protocol=2.
Initial Comment:
Compare:
>>> import pickle
>>> pickle.dumps(file('/etc/passwd'))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/pickle.py", line 1386, in dumps
Pickler(file, protocol, bin).dump(obj)
File "/usr/lib/python2.4/pickle.py", line 231, in dump
self.save(obj)
File "/usr/lib/python2.4/pickle.py", line 313, in save
rv = reduce(self.proto)
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
with
>>> pickle.dumps(file('/etc/passwd'), protocol=2)
'\x80\x02c__builtin__\nfile\nq\x00)\x81q\x01.'
Similarly, the __reduce__ method works for basic
objects like str, int or dict with protocol=2, but
doesn't work with protocol=1:
>>> (1).__reduce_ex__(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 int objects
>>> (1).__reduce_ex__(2)
(<function __newobj__ at 0xb7e5117c>, (<type 'int'>,
1), None, None, None)
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1474680&group_id=5470
More information about the Python-bugs-list
mailing list