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

Steve Holden steve at
Mon Jun 12 09:00:13 CEST 2006

digitalorganics at wrote:
> Fredrik Lundh wrote:
>>digitalorganics at wrote:
>>>Output from laptop comp.:
>>so how are you entering and running the code on your laptop ?
>>what happens if you set the class attribute to 100 instead of 10 ?
> You can see my other post which I just sent but, I was using PythonWin:
> 1. type code in editor
> 2. hit run
> 3. observe output in interactive window
Frankly I'd be less incredulous if you'd said you transferred the code 
between machines using some network- or file-based transfer mechanism. 
The facts are that if you have been entering "the same" code separately 
on two machines then by far the most likely source of any discrepancy is 
typographical error (a subject with which regular readers will know I am 
intimately familiar).

The Python behaviour you now understand (access to class variables in 
the absence of an eponymous instance variable) is long-standing, and it 
is therefore unlikely that two correct Python installations will give 
different results for the same code. Ergo, the two pieces of code are 

Unless, that is, you can tell us different beyond all possibility of 
transcription errors.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Love me, love my blog
Recent Ramblings

More information about the Python-list mailing list