Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104766 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2016-03-13 14:24 +0100 |
| Last post | 2016-03-13 14:24 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: problem using pickle Peter Otten <__peter__@web.de> - 2016-03-13 14:24 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-03-13 14:24 +0100 |
| Subject | Re: problem using pickle |
| Message-ID | <mailman.68.1457875466.12893.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web