Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Pickling Objects inherited from dict (Bug?)

Reply
Thread Tools

Pickling Objects inherited from dict (Bug?)

 
 
Thomas Guettler
Guest
Posts: n/a
 
      11-05-2003
Hi!

After unpickling the objects are not the same
any more. Is this a bug or feature?

import pickle

class MyDictContainer(dict):
def __init__(self):
dict.__init__(self)
print "MyDictContainer.__init__"

class MyDict(dict):
def __init__(self, root, name):
dict.__init__(self)
self.root=root
self.name=name

container=MyDictContainer()
for name in ["one", "two", "three"]:
mydict=MyDict(container, name)
container[name]=mydict

print container
file="data.pickle"
fd=open(file, "w")
pickle.dump(container, fd)
fd.close()

fd=open(file)
unpickle=pickle.load(fd)
fd.close()
print unpickle


Output:

===> python test-pickle.py
MyDictContainer.__init__
{'three': {}, 'two': {}, 'one': {}}
{'one': {},
'three': (<class '__main__.MyDictContainer'>,
<type 'dict'>, {'three': {},
'two': (<class '__main__.MyDictContainer'>, <type 'dict'>,
{'three': {}, 'two': {}, 'one': {}}), 'one': {}}), 'two':
(<class '__main__.MyDictContainer'>, <type 'dict'>,
{'three': {}, 'two': {}, 'one': {}})}

After unpickling the object is not the same anymore.
Any hints?

If I inherit from UserDict instead, the is no error.

thomas

 
Reply With Quote
 
 
 
 
Michael Hudson
Guest
Posts: n/a
 
      11-05-2003
"Thomas Guettler" <(E-Mail Removed)> writes:

> Hi!
>
> After unpickling the objects are not the same
> any more. Is this a bug or feature?


There's a bug report up on SF that may be relavent, try searching
(unfortunately I don't remember the details...).

Cheers,
mwh

--
The use of COBOL cripples the mind; its teaching should, therefore,
be regarded as a criminal offence.
-- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pickling a circular object inherited from list Klaus Kopec Python 4 12-10-2008 10:03 AM
Pickling and unpickling inherited attributes Alex Python 9 11-02-2005 02:59 AM
[OT] nntp references, was re: pickling a dict Dan Perl Python 0 11-03-2004 12:25 PM
pickling subclasses of dict/list Edward Loper Python 1 07-04-2004 03:28 PM
Pickling object inherited from dict Thomas Guettler Python 1 10-28-2003 09:04 AM



Advertisments