I have 2 python modules (modA.py and modB.py). I want to run modA.py from modB.py. How do I do that? If I import modA.py in modB.py, then I can access the functions and classes in modA.py, but how can I actually execute modA.py (all of it)?
Here's an example case:
-- modA.py --
print "Hello! I'm ModA"
How should I write modB.py so that after executing modB.py I get the output:
"Hello! I'm modA"
EDIT: In the comments it's mentioned that importing is executing the module. This is very helpful information. Thanks for that. However, there's a slight problem. What if I have:
--- modB.py ---
# execute modA.pyimport modA.py print "some ModB.py stuff here"# execute modA.py againimport modA.py
In this case, it doesn't execute modA.py a second time as it has already imported it. I guess maybe, is there a way to "unimport" the module? Even though, doesn't seem like an elegant solution. Doesn't Python have a way to simply execute another module?