i don't really understand member variables..

gabor gabor at realtime.sk
Thu Oct 24 02:54:16 CEST 2002


hi,

until now i thought i understand member variables...

but now i don't :-):

example:
>>> class Test:
...     data = []
... 
>>> a = Test()
>>> a.data.append("x")
>>> a.data
['x']
>>> b = Test()
>>> b.data
['x']

so they are shared?
but now:

>>> b.data = ["y"]
>>> b.data
['y']
>>> a.data
['x']

now they aren't anymore....

so if i define some data after the class... line then those are static (
as in c++?) but why the stop being static in the second code-example?

i kind of begin to understand this, but could someone clarify this?

thanks,
gabor




-- 
listening to Keitaro Takanami - Morning,Morning
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20021024/c2403418/attachment.pgp>


More information about the Python-list mailing list