In my script I call an executable with optional command line argument (if passed, this argument switches on a function in the executable, which is off by default). I want to control this option directly from argument of the script itself. Write now I do:
import subprocess option = False if option: check = subprocess.Popen(['executable', '--option']) else: check = subprocess.Popen(['executable']) I tried to find a more compact way:
import subprocess option = False check = subprocess.Popen(['executable', '--option' if option else '']) But this raises error "Unknown option" in the exactable itself.
And this raises error in python:
import subprocess option = False check = subprocess.Popen(['executable', '--option' if option else None]) So, my question: is there a way to pass an optional argument to subprocess in one line?