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):
There are Python decorators @staticmethod
and @classmethod
, which you can use to declare a method static or class-related. This should help accessing your class data element:
class MyClass:
__a = 0
@staticmethod
def getA():
return MyClass.__a
class MyOtherClass:
def DoSomething(self):
print MyClass.getA() + 1
Example inspired by this source: http://www.rexx.com/~dkuhlman/python_101/python_101.html