-4

this is related to this: Execute a file with arguments in Python shell

the question is: what if the py file accepts options like this:

Options: -h, --help show this help message and exit -f FOLDER, --folder=FOLDER etc.

then how to pass options to the call?

Community
  • 1
  • 1
MahD
  • 3
  • 2

1 Answers1

1

The same way as in the question you linked.

subprocess.call(['./abc.py', '--help'])

or

subprocess.call(['./abc.py', '-f', 'FOLDER'])

You can think the list of flags and options supplied for the call-method just as different way to passing those arguments. If you would call that python-file normally from command-line, you would supply those arguments separated with space, so in a way it is a space separated list. Here the same list is supplied, just in a different format, where each , separates the arguments instead of the space.

Teemu Risikko
  • 1,145
  • 10
  • 16