Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107748

Re: Differences between Class(Object) and Class(Dict) for dictionary usage?

From Michael Torrie <torriem@gmail.com>
Newsgroups comp.lang.python
Subject Re: Differences between Class(Object) and Class(Dict) for dictionary usage?
Date 2016-04-27 21:52 -0600
Message-ID <mailman.166.1461815577.32212.python-list@python.org> (permalink)
References <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> <57218905.5090807@gmail.com>

Show all headers | View raw


On 04/27/2016 08:49 PM, Christopher Reimer wrote:
> On 4/27/2016 7:00 PM, Michael Torrie wrote:
>> I am guessing that the reason you are storing state as it's own 
>> dictionary is so that you can pass the state itself to the constructor? 
> 
> Someone said it was bad to store the object itself to file (my original 
> plan) and that I should use a dictionary instead. This is my 
> implementation of that idea. However, saving and loading data is far 
> down my to do list.

Pickle should be able to serialize an object that stores state as
attributes, as that's what objects normally do.

But you could also serialize and save the objects yourself manually too.
 In fact if it were me I would save game state to some kind of ini file,
which would mean manually going through each object and writing out the
relevant data to the ini file using the right syntax. And then reverse
the process when restoring from a file.  XML could be another format
used for your file, if you're into that kind of thing.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Michael Torrie <torriem@gmail.com> - 2016-04-27 21:52 -0600

csiph-web