Difference between __init__ (again) and nothing ...

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Jan 2 07:54:23 EST 2007


Stef Mientki a écrit :
> Marc 'BlackJack' Rintsch wrote:
> 
>> In <da749$459a380d$d443bb3a$16845 at news.speedlinq.nl>, Stef Mientki wrote:
>>
>>> What's the difference between using __init__ and using nothing,
>>> as the examples below.
>>>
>>> class cpu:
>>>    PC = 4
>>
>>
>> This is a *class attribute*.  It's the same for all instances of `cpu`.
>>
>>> class cpu:
>>>    def __init__:
        def __init__(self):
>>>      self.PC = 4

By convention, ALL_UPPER names have a 'symbolic constant' semantic. 
Since Python is a very 'free' language (no attribute access restriction, 
no symbolic constants etc), it *strongly* relies on conventions.


>>
>> This is an *instance attribute* which is set in every instance of `cpu`.
>>
> thanks Marc,
> 
> Oh so obvious, why didn't I discovered that myself ;-)

Perhaps because it may not be that obvious at first sight ?-)

(that is, until you really understand Python's object model, which is 
really different from most mainstream OOPLs object models...)



More information about the Python-list mailing list