[ python-Bugs-640645 ] cPickle.dumps change after for
SourceForge.net
noreply at sourceforge.net
Mon Jan 12 07:30:58 EST 2004
Bugs item #640645, was opened at 2002-11-19 11:42
Message generated for change (Comment added) made by arigo
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640645&group_id=5470
Category: Python Library
Group: Not a Bug
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Marco Beri (marcoberi)
Assigned to: Nobody/Anonymous (nobody)
Summary: cPickle.dumps change after for
Initial Comment:
try this program:
import cPickle
a=([{}])
print cPickle.dumps(a)
for x in a:
pass
cPickle.dumps(a)
It prints:
(lp1
(da.
Why on earth it does dumps return different string?
And after just a for with a pass in it...
----------------------------------------------------------------------
>Comment By: Armin Rigo (arigo)
Date: 2004-01-12 12:30
Message:
Logged In: YES
user_id=4771
Someone else ran into the problem of unexpectedly varying
cPickle strings:
http://sourceforge.net/tracker/?func=detail&atid=429622&aid=875331&group_id=41036
Maybe this behavior should be documented.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-11-19 16:19
Message:
Logged In: YES
user_id=31435
Closed as Not-A-Bug. The internals of pickle strings aren't
guaranteed, just that "they work" when unpickled again, and
these do. If you want a hash code for a dict, don't dare use
pickle for this either, even if it appears "to work": it doesn't.
The order in which dict keys are enumerated isn't defined
either, and can and does vary across releases, and even
across program runs.
So a reliable hash code for a dict needs to be independent of
key iteration order, and no version of pickle spends time
trying to force that issue (waste of time -- it isn't needed for
pickling or unpickling).
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-11-19 14:35
Message:
Logged In: YES
user_id=6656
Well, that's asking for something you're not promised. It
takes some imagination to categorize this as a bug, and I'm
not going to put any of my time into fixing it.
It seems using pickle in place of cPickle *may* work, fwiw.
----------------------------------------------------------------------
Comment By: Marco Beri (marcoberi)
Date: 2002-11-19 13:56
Message:
Logged In: YES
user_id=588604
I would like to use hash(cPickle.dumps(a)) to have a unique
hash also for dict that aren't hashable.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-11-19 13:03
Message:
Logged In: YES
user_id=6656
OK, I think I know what's happening.
Look at this:
>>> a = {}
>>> cPickle.dumps(a)
'(dp1\n.'
>>> cPickle.dumps({})
'(d.'
the only difference is in the number of references to the
object getting pickled. I don't know why that matters, but
it seems to.
Why does this matter to you?
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-11-19 12:56
Message:
Logged In: YES
user_id=6656
You're right, sorry.
----------------------------------------------------------------------
Comment By: Marco Beri (marcoberi)
Date: 2002-11-19 12:07
Message:
Logged In: YES
user_id=588604
I forgot to print the second dumps but the bug remains:
Before the for:
(lp1
(da.
After the for:
(lp1
(dp2
a.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-11-19 12:00
Message:
Logged In: YES
user_id=6656
Umm:
>>> a=([{}])
>>> cPickle.dumps(a)
'(lp1\n(da.'
you're only printing the first pickle...
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640645&group_id=5470
More information about the Python-bugs-list
mailing list