Reputation: 1186
I am trying to run a python script from another python script. When I call the second script, I want to pass a variable to it.
For instance,
Let's say I have python module A (A.py) and it has the variable oDesktop. When I run a second module B.py, I want to be able to access that oDestkop variable. I am not sure how to do this.
pseudocode:
A.py
oDesktop = DesktopClass();
# RUN SOME CODE
run_module("B.py", oDesktop)
B.py
oDesktop.some_func();
To clarify, I do not have a main in B.py. I have some global variable that I need to keep global.
Upvotes: 0
Views: 171
Reputation: 2467
from A import*
That way your global variables should remain global to both program and module and you can run functions as you would should you have written them in the same program. NB if program A auto runs sections, just place it under
if __name__ == "__main__":
where this will only run should A be started initially.
Upvotes: 1