Is there a way to get a reference to the local variables defined in a different module?
for example, I have two files: framework.py and user_code.py:
framework.py:
from kivy.app import App
class BASE_A:
pass
class MyApp(App):
def on_start(self):
'''Here I'd like to get a reference to sub-classes of BASE_A and
instantiated objects of these sub-classes, defined in the file
"user_code.py" such as a1, a2, as well as the class A itself,
without explicitly passing them to MyApp's instance.
'''
user_code.py:
from framework import MyApp
class A(BASE_A):
pass
app = MyApp()
a1 = A()
a2 = A()
app.run()
What I'd like to do is to somehow get a reference to the objects a1 and a2, as well as the class A, that were all defined in user_code.py. I'd like to use them in the method on_start, which is invoked in app.run().
Is it possible, for example, to get a reference to the scope in which the MyApp object was defined (user_code.py)?
Some background for anyone who's interested:
I know it's a bit of an odd question, but the reason is:
I'm writing a python framework for creating custom-made GUI control programs for self-made instruments, based on Arduino. It's called Instrumentino (sitting in GitHub) and I'm currently developing version 2.
For people to use the framework, they need to define a system description file (user_code.py in the example) where they declare what parts they're using in their system (python objects), as well as what type of actions the system should perform (python classes).
What I'm trying to achieve is to automatically identify these objects and classes in MyApp's on_start without asking the user to explicitly pass these objects and classes, in order to make the user code cleaner. Meaning to avoid code such as:
app.add_object(a1)
app.add_object(a2)
app.add_class(A)