Global variables within classes.
Kevac Marko
mkevac at gmail.com
Tue Nov 27 17:54:05 EST 2007
On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>
> Don't think so. It's a surprise for many but then class attributes are
> not that common in code or they even use this "gotcha" for
> immutable default values. As long a the value isn't changed the default
> value is just referenced from the class then and not every instance.
>
When changing default value, is there any way to change class
attribute and all referenced attributes too?
class M:
name = u"Marko"
a, b = M(), M()
a.name = u"Kevac"
print M.name, a.name, b.name
-> Marko Kevac Marko
Is there any way to get here -> Kevac Kevac Kevac ?
Or what is the right way of keeping global variables in classes?
More information about the Python-list
mailing list