Class attribute or instance attribute?

Asun Friere afriere at yahoo.co.uk
Tue Apr 29 00:50:41 EDT 2003


mis6 at pitt.edu (Michele Simionato) wrote in message news:<2259b0e2.0304281329.12ac184b at posting.google.com>...
> "Paul Watson" <pwatson at redlinec.com> wrote in message news:<vaqtlsqbi52j93 at corp.supernews.com>...
> > When is an attribute a class attribute or an instance attribute?
> 
> I give you a subtle example:
> 
On the other hand here is a totally obvious example illustrating the same ;-)

class Foo (object) :
    foo = 'spam'
    def __init__ (self) :
        print Foo.foo, self.foo
        self.foo = 'ham'
        print Foo.foo, self.foo

>>> f = Foo()
spam spam
spam ham
>>> print f.foo, Foo.foo
ham spam




More information about the Python-list mailing list