I have a file a.py
avariable = None
class a():
def method(self):
global avariable
avariable = 100
print "variable is", avariable
and a file b.py
from a import *
class b(a,):
def mymethod(self):
a().method()
print "avariable is " , avariable
if __name__ == '__main__':
b().mymethod()
File b
imports everything from a
and also inherits from a
.
a
's method
is called and the avariable
is change to 100 but when I print avariable
in b the value is None
. How to I use in class b
the variable avariable
that a
class changed?
Output:
>python b.py
variable is 100
avariable is None
Clarification
It's crucial for me to use
from a import *
because I have already code in class b that calls methods of class a using the syntax
self.method()
and that cannot change.
i.e.
from a import *
class b(a):
def mymethod(self):
self.method()
print "avariable is " , avariable
if __name__ == '__main__':
b().mymethod()
So is there a way to access the variable avariable
in a without prefixing in any way the
avariable
?