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

2016-04-27 Thread Ethan Furman
On 04/27/2016 09:06 PM, Christopher Reimer wrote: On 4/27/2016 8:52 PM, Michael Torrie wrote: 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.

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

2016-04-27 Thread Michael Torrie
On 04/27/2016 10:06 PM, Christopher Reimer wrote: > On 4/27/2016 8:52 PM, Michael Torrie wrote: >> 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 sy

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

2016-04-27 Thread Christopher Reimer
On 4/27/2016 8:52 PM, Michael Torrie wrote: 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 fi

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

2016-04-27 Thread Christopher Reimer
On 4/27/2016 8:05 PM, Ethan Furman wrote: I ripped out the fetch_state because that will take more work -- you can't pass a Pawn's saved state in to Piece and get the results you want. pickle is worth looking at for saving/restoring. The original idea was to pass a Pawn dictionary to the cons

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

2016-04-27 Thread Michael Torrie
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

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

2016-04-27 Thread Christopher Reimer
On 4/27/2016 7:07 PM, Ben Finney wrote: I would say the latter is more Pythonic, because it: * Better conveys the intention (“set the value of the ‘self.key’ attribute”). * Uses the built-in mechanisms of Python (don't invoke magic attributes, instead use the system that makes use of them

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

2016-04-27 Thread Ethan Furman
On 04/27/2016 06:12 PM, Christopher Reimer wrote: After considering the feedback I got for sanity checking my code, I've decided to simplify the base class for the chess pieces (see code below). All the variables are stored inside a dictionary with most values accessible through properties. A cu

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

2016-04-27 Thread Christopher Reimer
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

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

2016-04-27 Thread Christopher Reimer via Python-list
On 4/26/2016 8:56 PM, Random832 wrote: what exactly do you mean by property decorators? If you're just accessing them in a dictionary what's the benefit over having the values be simple attributes rather than properties? After considering the feedback I got for sanity checking my code, I've d

Pythonic style (was: Differences between Class(Object) and Class(Dict) for dictionary usage?)

2016-04-27 Thread Ben Finney
Christopher Reimer writes: > On 4/27/2016 7:33 AM, Ian Kelly wrote: > > > self.__dict__ = {'key', 'value'} > > > > self.key = value > > Which expression is Pythonic? (Note that assignment is not an expression in Python; assigment is a statement.) > I've seen both used in various examp

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

2016-04-27 Thread Michael Torrie
On 04/27/2016 07:12 PM, Christopher Reimer wrote: > class Piece(object): > def __init__(self, color, position, state=None): > if state is None: > self._state = { > 'class': self.__class__.__name__, > 'color': color, > 'fi

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

2016-04-27 Thread Christopher Reimer
On 4/27/2016 7:33 AM, Ian Kelly wrote: This class definition looks muddled. Because Test2 inherits from dict, the object referred to by "self" will be a dict, and self.__dict__ is actually a *different* dict, containing the attributes of self. The line: self.__dict__ = {'key', 'value'} is

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

2016-04-27 Thread Christopher Reimer
On 4/27/2016 7:24 AM, Ian Kelly wrote: Some other great questions to ask yourself are "do I really want len(my_object) to return the number of items in this dict" and "do I really want list(my_object) to return all the keys in this dict"? If the answer to all those is yes, then it's probably fa

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

2016-04-27 Thread Christopher Reimer
On 4/26/2016 8:56 PM, Random832 wrote: what exactly do you mean by property decorators? If you're just accessing them in a dictionary what's the benefit over having the values be simple attributes rather than properties? After considering the feedback I got for sanity checking my code, I've d

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

2016-04-27 Thread Ian Kelly
On Tue, Apr 26, 2016 at 9:43 PM, Christopher Reimer wrote: > class Test2(dict): > def __init__(self): > self.__dict__ = {'key', 'value'} This class definition looks muddled. Because Test2 inherits from dict, the object referred to by "self" will be a dict, and self.__d

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

2016-04-27 Thread Ian Kelly
On Tue, Apr 26, 2016 at 11:31 PM, Ethan Furman wrote: > On 04/26/2016 08:43 PM, Christopher Reimer wrote: > >> If I'm using a dictionary to store variables for an object, and >> accessing the variable values from dictionary via property decorators, >> would it be better to derive the class from ob

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

2016-04-26 Thread Ethan Furman
On 04/26/2016 08:54 PM, Ben Finney wrote: (Note that “allow attribute-syntax access to dictionary items” does not qualify as “better”, IMO; it qualifies as “needlessly confusing distinct concepts”.) Well, since one of the side-effects of class instances is to provide "attribute-syntax access

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

2016-04-26 Thread Ethan Furman
On 04/26/2016 08:43 PM, Christopher Reimer wrote: If I'm using a dictionary to store variables for an object, and accessing the variable values from dictionary via property decorators, would it be better to derive the class from object or dict? class Test1(object): def __init__(se

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

2016-04-26 Thread Random832
On Tue, Apr 26, 2016, at 23:43, Christopher Reimer wrote: > Greetings, > > If I'm using a dictionary to store variables for an object, and > accessing the variable values from dictionary via property decorators, what exactly do you mean by property decorators? If you're just accessing them in a

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

2016-04-26 Thread Ben Finney
Christopher Reimer writes: > If I'm using a dictionary to store variables for an object, and > accessing the variable values from dictionary via property decorators Why not use the built-in ‘dict’ type? What does the new type do which isn't already better served by the built-in ‘dict’ type? (N

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

2016-04-26 Thread Christopher Reimer
Greetings, If I'm using a dictionary to store variables for an object, and accessing the variable values from dictionary via property decorators, would it be better to derive the class from object or dict? class Test1(object): def __init__(self): self.state = {'key': '