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

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


digitalorganics at gmail.com wrote:
> Fredrik Lundh wrote:
> 
>>digitalorganics at gmail.com wrote:
>>
>>
>>>Output from laptop comp.:
>>>
>>>1
>>>10
>>>2
>>>10
>>>3
>>>10
>>
>>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 ?
>>
>></F>
> 
> 
> 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 
different.

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

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list