newbie question on class vars

Sean 'Shaleh' Perry shalehperry at
Tue Oct 8 01:06:26 CEST 2002

On Monday 07 October 2002 15:46, JXSternChangeX2R wrote:
> Oops, come to think of it, I did mean it to be by instance.
> Tho my syntax question, remains.
> J.

then you want:

class Foo:
    def __init__(self):
        self.__myvar = 1

yes, you must use self (or whatever you call the variable).  This is just the 
way things are.  You learn to prefer it after using Python for a while and 
then going back to other languages.

if you place the variable as:

class Foo:
    myvar = 1
    def __init__(self): pass

then you are making the variable global to all instances of the class as I 
demonstrated in my last mail.

More information about the Python-list mailing list