Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Torrie Newsgroups: comp.lang.python Subject: Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Date: Wed, 27 Apr 2016 21:52:37 -0600 Lines: 21 Message-ID: References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> <57218905.5090807@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de OZZtiB01ettfyCQTc65mSg9hX7r4X7eVZFC3rjVXtNKg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.039 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'subject:Object': 0.09; 'file,': 0.15; 'instead.': 0.15; 'subject: \n ': 0.15; 'attributes,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'guessing': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'storing': 0.16; 'subject:between': 0.16; 'subject:usage': 0.16; 'wrote:': 0.16; 'do.': 0.22; 'file.': 0.22; 'pass': 0.22; 'xml': 0.24; 'header:In-Reply-To:1': 0.24; 'header :User-Agent:1': 0.26; '(my': 0.29; 'dictionary': 0.29; 'pickle': 0.29; 'objects': 0.29; 'too.': 0.30; 'normally': 0.30; 'another': 0.32; 'subject:) ': 0.32; 'michael': 0.33; 'loading': 0.33; 'message-id:@gmail.com': 0.34; 'file': 0.34; 'could': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'list.': 0.37; 'itself': 0.38; 'someone': 0.38; 'mean': 0.38; 'data': 0.39; 'format': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'save': 0.60; 'your': 0.60; 'charset:windows-1252': 0.62; 'reverse': 0.66; 'saving': 0.70; 'yourself': 0.73; '7:00': 0.84; 'ini': 0.84; 'subject:Class': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-Reply-To: <57217A2B.4060709@icloud.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <57218905.5090807@gmail.com> X-Mailman-Original-References: <57216399.1050702@icloud.com> <57216EA8.4060600@gmail.com> <57217A2B.4060709@icloud.com> Xref: csiph.com comp.lang.python:107748 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.