I have written a script which in turn runs some other code and I need to check some conditions in latter code before it gets executed! So i thought of using command line arguments and I don’t have better knowledge on OOP concepts to write classes which was recommended in most of the answers given for similar questions in stack overflow.
can I pass arguments like this
subprocess.call([sys.executable, 'Cnt1', 'argument1', 'argument2'])
If I can, how to read the arguments in the latter code?
I tried to print
print sys.executable
print Cnt1
its showing error for print Cnt1
You can indeed run
pythonusing thesubprocessmodule, and pass arguments to that. In essence you’d be running a completely new program; this is not the same as calling a function. Usually there is no need to go to such drastic lengths though.If you do run a separate python script, you need to parse the arguments passed from
sys.argv. Theargparsemodule makes that easier but is not required if all you do is pass a list of arguments.