[Python-bugs-list] [ python-Bugs-640645 ] cPickle.dumps change after for
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 19 Nov 2002 05:56:41 -0800
Bugs item #640645, was opened at 2002-11-19 11:42
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=640645&group_id=5470
Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: Invalid
Priority: 5
Submitted By: Marco Beri (marcoberi)
Assigned to: Michael Hudson (mwh)
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: 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