I have scripts:
moving1.py:
def move():
print("walk!")
moving2.py:
def move():
print("run!")
And man.py, that can accept by argument parameter moving1 or moving2 script to act.
man.py:
import sys
if len(sys.argv) <= 1:
exit("Too less arguments calling script")
__import__(sys.argv[1])
moving = sys.modules[sys.argv[1]]
def move():
moving.move()
Now I have testman.py script, that have to test all variants of man.py execution:
testman.py
import man #and somehow add here as argument "moving1"
man.move()
import man #and somehow add here as argument "moving2"
man.move()
There exist a lot of similar questions, but they don't do exactly what I want. How can I add arguments to imported scripts? Problem is not to check
if __name__ = "__main__":
there, problem is to import script exactly with parameters I want. Is it possible?
argparseto define the command line interface.