[Tutor] Change to Class-level Variable

Robert webtourist at gmail.com
Mon Oct 4 00:06:39 CEST 2010


Why is "f1" not affected by the Class-level variable change below ?

>>> class Foo( object ):
...     myid = 'Foo'
...     def __init__( self ):
...        pass
...
>>> f1 = Foo()
>>> f2 = Foo()
>>> f1.myid = 'Bar'
>>> Foo.myid = 'SPAM'
>>> f1.myid         <----------------------- Why is "f1" not affected by the Class variable change ?
'Bar'
>>> f2.myid
'SPAM'
>>> f4 = Foo()
>>> f4.myid
'SPAM'
>>>


More information about the Tutor mailing list