How to pass Python command line options (vs arguments) when running script directly vs via Python interpreter?

Thomas Jollans tjol at tjol.eu
Wed Aug 15 04:22:50 EDT 2018


On 14/08/18 23:45, Malcolm Greene wrote:
> When you run a script via "python3 script.py" you can include command
> line options like -b, -B, -O, -OO, etc between the "python3" interpreter
> reference and the script.py file, eg. "python3 -b -B -O -OO script.py".
> When you create a script that is executable directly, eg. script.py with
> execution bit set on Linux or on Windows where the .py file extension is
> associated with a specific Python executable, there doesn't appear to be
> a way to pass command line options to the script. In this later case,
> how can I pass my script command line options without having these
> options confused with command line arguments?
> Thank you,
> Malcolm
> 

If you really want to, you can pass a *single* argument in your #! line,
e.g.:

#!/usr/bin/python3 -Wd



More information about the Python-list mailing list