Pickling object inherited from dict
From: Thomas Guettler (guettli_at_thomas-guettler.de)
Date: 10/27/03
- Next message: Fergus Henderson: "Re: Test cases and static typing"
- Previous message: Eric Brunel: "Python 2.3: socket.gethostbyname(socket.gethostname()) fails?"
- Next in thread: Thomas Guettler: "Re: Pickling object inherited from dict"
- Reply: Thomas Guettler: "Re: Pickling object inherited from dict"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Oct 2003 17:19:08 +0100
Hi!
If I pickle a class which inherits from dict,
I don't get the same data again, if I unpickle
it.
def test_pickle():
home="..."
server=WorkflowServer(home)
server.save()
print server.users.items() # 1
unpickle=load(home)
print unpickle.users.items() #2
def load(home):
file=os.path.join(home, "data.pickle")
fd=open(file)
server=pickle.load(fd)
fd.close()
assert(server.__class__==WorkflowServer)
return server
WorkflowServer:
def save(self):
file=os.path.join(self.home, "data.pickle")
fd=open(file, "w")
pickle.dump(self, fd)
fd.close()
class User(dict):
....
class UserManagemente(dict):
.... # server.users
If I run test_pickle() I get this result: (See #1 and #2)
[('EGSADMIN', {}), ('TEST', {})]
[('EGSADMIN', {}), ('TEST', (<class '__main__.UserManagement'>,
<type 'dict'>, {'EGSADMIN': {}, 'TEST': {}}))]
Why are the two lines different? Sorry, I was not able
to make a smaller working example today.
thomas
Python 2.2.2
- Next message: Fergus Henderson: "Re: Test cases and static typing"
- Previous message: Eric Brunel: "Python 2.3: socket.gethostbyname(socket.gethostname()) fails?"
- Next in thread: Thomas Guettler: "Re: Pickling object inherited from dict"
- Reply: Thomas Guettler: "Re: Pickling object inherited from dict"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|