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

Terry Reedy tjreedy at udel.edu
Tue Aug 14 18:08:53 EDT 2018


On 8/14/2018 5:45 PM, 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".

More generally,

python <python options> script.py <script options>

Many python options can also be specified by environmental variables.

> 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.

If you run the script directly, by entering >script.py or clicking a 
script icon or name in File Explorer, it runs python without python 
options *other than those specified in environmental variables*.

 > In this later case,
> how can I pass my script command line options without having these
> options confused with command line arguments?

Command line arguments are arguments for command line options.  For 
instance, in '-m idlelib', '-m' is the option 'run a module as __main__' 
and 'idlelib' is the argument (which here means 
Lib/idlelib/__main__.py).  Do you mean 'python option' versus 'script 
option'?


-- 
Terry Jan Reedy




More information about the Python-list mailing list