Re: Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread Russell Warren
Thanks for the additional examples, David (didn't see this before my last post). All of it makes sense now, including those examples. Russ -- http://mail.python.org/mailman/listinfo/python-list

Re: Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread Russell Warren
D'oh... I just realized why this is happening. It is clear in the longhand as you say, but I don't think in the way you descibed it (or I'm so far gone right now I have lost it). self.I += 1 is the same as self.I = self.I + 1 and when python tries figures out what the 'self.I' is on the ri

Re: Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread David Wahler
Russell Warren wrote: > Not true as above. The longhand for 'self.I += 1' is 'self.I = self.I > + 1', which normally needs self.I to exist due to the RHS of this. Try this: >>> class foo(object): ... I = 1 ... def __init__(self): ... print self.__dict__ ... self.I = self.I + 1 ...

Re: Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread Russell Warren
> I can see how this can be confusing, but I think the confusion here is > yours, not Pythons ;) This is very possible, but I don't think in the way you describe! > self.I += 10 is an *assignment*. Like any assignment, it causes the > attribute in question to be created ... no it isn't. The +=

Re: Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread Chris Mellon
On 16 Jan 2006 14:11:25 -0800, Russell Warren <[EMAIL PROTECTED]> wrote: > I just ran across a case which seems like an odd exception to either > what I understand as the "normal" variable lookup scheme in an > instance/object heirarchy, or to the rules regarding variable usage > before creation.

Implied instance attribute creation when referencing a class attribute

2006-01-16 Thread Russell Warren
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable usage before creation. Check this out: >>> class foo(object): ... I = 1 ... def __init__(self): ...