I have run into the following issue in Python. Suppose you have 3 files:
1) a.py (defines class A):
class A:
def a_method(self):
print "global var experiment"
2) b.py (defines class B that uses method of the global object of class A):
class B:
def b_method(self):
print "calling a_method() from B..."
obj_a.a_method()
3) global_ex.py:
from a import A
obj_a=A()
obj_a.a_method()
from b import B
obj_b = B()
obj_b.b_method()
When I run global_ex.py I get the error:
NameError: global name 'obj_a' is not defined
If instead of importing a.py and b.py I copy-paste them into the global_ex.py it works fine.
What is the issue here? Generally, What is the best way to use methods of one object in another object?
Thank you in advance.
obj_ais not defined in the global scope ofb.py- would you like the interpreter to copy-paste the text of the imported module instead of using compiled bytecode?