Access static class variable of parent class in Python
Posted
by fuenfundachtzig
on Stack Overflow
See other posts from Stack Overflow
or by fuenfundachtzig
Published on 2010-06-18T14:39:50Z
Indexed on
2010/06/18
14:43 UTC
Read the original article
Hit count: 295
I have someting like this
class A:
__a = 0
def __init__(self):
A.__a = A.__a + 1
def a(self):
return A.__a
class B(A):
def __init__(self):
# how can I access / modify A.__a here?
A.__a = A.__a + 1 # does not work
def a(self):
return A.__a
Can I access the __a
static variable in B
? It's possible writing a
instead of __a
, is this the only way? (I guess the answer might be rather short: yes :)
© Stack Overflow or respective owner