Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104766
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: problem using pickle |
| Date | 2016-03-13 14:24 +0100 |
| Organization | None |
| Message-ID | <mailman.68.1457875466.12893.python-list@python.org> (permalink) |
| References | <CAKafoGCO5=X-mA5usiTLAdztXKnLCsDpvoquB=DM6t0-7EKxFQ@mail.gmail.com> |
Nicky Mac wrote: > Dear Python team, > I have studied the excellent documentation, That is always a laudable endeavour ;) > and attempted to make use of > pickle thus: > > filename = 'my_saved_adventure' > import pickle > class object: 'object' already is the name for a Python built-in; you should avoid redefining it. > def __init__(self,i,.........t) : > self.id = i > ..... > > class world: > def __init__(self): > self.object > > class object: As you already defined 'object' above you now have a name clash with your own stuff. I suppose that is because what you post is not your actual code. > def __init__(self,i, > > .....then Object instances of object are created ........ > > myworld = world; > myworld.Object = Object > fileobj = open(filename,'wb') > pickle.dump(myworld,fileobj); fileobj.close() > result = "saved your game to " + filename > > fileobj = open(filename,'rb') > myworld = pickle.load(fileobj); fileobj.close() > Object = myworld.Object > result = "restored your game from " + filename > > > The proecedures execute without error > but a file of only 21b is created containing " €c__main__world q . > altho there are several k of object instance data. Unfortunately I cannot tell what might have gone wrong from the outline you provide above. Can you make a smaller script that shows the same problem, and that you can post in its entirety here? Use cut and paste, do not retype! Thank you.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: problem using pickle Peter Otten <__peter__@web.de> - 2016-03-13 14:24 +0100
csiph-web