direct initialization of class attributes vs. declarations w/in __init__

digitalorganics at gmail.com digitalorganics at gmail.com
Sun Jun 11 17:34:29 EDT 2006


Fredrik Lundh wrote:
> digitalorganics at gmail.com wrote:
>
> > At first, I thought that self.jerk was resolving to the class attribute
> > instead of creating a new variable (w/ a differing scope).
>
> When you access an instance attribute, Python first looks in the
> instance object, and then in the class object.
>
> When you assign to an instance attribute, it's *always* assigned to the
> instance object, whether there's a class attribute with the same name or
> not.
>
> If there's already a class attribute with the same name, that attribute
> will be shadowed (but can still be accessed via the class object, of
> course).
>
> > It doesn't work this way on my laptop...
>
> Python's always worked that way, so I find that a bit hard to believe.
>

No need to be obnoxious. I do appreciate your efforts to help, but you
must admit, your last statement is a bit snide and certainly not
useful. I'm telling you that the code runs differently on my laptop.
Why this is, I don't know any more /or/ less than you do apparently.
Now, it is of course possible that I'm interpreting the results
incorrectly, but that doesn't change the fact that I'm getting
different results per computer with identical code.




More information about the Python-list mailing list