[Python-au] Class attribute behaviour wierdisms

Anthony Baxter anthony at interlink.com.au
Tue Feb 21 05:34:56 CET 2006

On Tuesday 21 February 2006 15:15, Darryl Ross wrote:
> Hey All,
> Just wondering whether this would be expected behaviour??
> > darryl at mail:~$ cat test.py
> > class Blah:
> >     attr = []

Yes, this is expected behaviour. You've created a class here, and 
given the class an attribute 'attr' that's a list. Code in the class 
body applies to the class. If you want per-instance stuff, put it in 
a method, for instance, __init__. 

Anthony Baxter     <anthony at interlink.com.au>
It's never too late to have a happy childhood.

More information about the python-au mailing list