__init__ & attributes clarification

Erik Max Francis max at alcyone.com
Sun Feb 2 20:39:55 EST 2003


Afanasiy wrote:

> Are these two, in effect, the same?
> 
> class hive:
>   workers = []
> 
> ...
> 
> class hive:
>   def __init__(self):
>     self.workers = []

No.  The first defines a class attribute, common to all instances (and
present in the class itself; the latter defines an instance attribute). 
If both assignments were present, the instance attribute would override
the class attribute, but they are by no means the same thing.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ The quickest way of ending a war is to lose it.
\__/ George Orwell
    REALpolitik / http://www.realpolitik.com/
 Get your own customized newsfeed online in realtime ... for free!




More information about the Python-list mailing list