Command lines are used to launch Python programs from a system shell prompt. Command-line options intended for Python itself appear before the specification of the program code to be run. Options intended for the code to be run appear after the program specification. Command lines have the following format:
python [option*
] [scriptfilename
| -ccommand
| -mmodule
| - ] [arg*
]
-b
Issues warnings for calling str()
with a bytes
or bytearray
object, and comparing a
bytes
or bytearray
with a str
. Option -bb
issues errors instead.
-B
-d
Turns on parser debugging output (for developers of the Python core).
-E
Ignores Python environment variables described ahead (such
as PYTHONPATH
).
-h
Prints help message and exit.
-i
Enters interactive mode after executing a script. Useful for postmortem debugging.
-O
Optimizes generated byte-code (create and use .pyo byte-code files). Currently yields a minor performance improvement.
-OO
Operates like -O
, the
previous option, but also removes docstrings from
byte-code.
-s
Do not add the user site directory to the sys.path
module search path.
-S
-u
-v
Prints a message each time a module is initialized, showing the place from which it is loaded; repeats this flag for more verbose output.
-V
-W
arg
Functions as warning control; arg
takes the form
action
:
message
:
category
:
module
:
lineno
.
See warnings
module
documentation in the Python Library Reference manual (available
at http://www.python.org/doc/).
-x
Skips first line of source, allowing use of non-Unix
forms of #!cmd
.
scriptfilename
Denotes the name of a Python scriptfile to execute as the
main, topmost file of a program execute (e.g., python main.py
). The script’s name is
made available in sys.argv[0]
.
-c
command
Specifies a Python command (as a string) to execute (e.g.,
python -c "print('spam' * 8)"
runs a print call). sys.argv[0]
is set to -c
.
-m
module
Runs library module as a script: searches for module on
sys.path
, and runs it as a
top-level file (e.g., python -m
profile
runs the Python profiler located in a standard
library directory). sys.argv[0]
is set to the module’s
full path name.
−
Reads Python commands from stdin (the default); enters
interactive mode if stdin
is a tty (interactive device). sys.argv[0]
is set to −
.
arg
*
Indicates that anything else on the command line is passed
to the scriptfile or command (and appears in the built-in list
of strings sys.argv[1:]
).
If no scriptfilename
,
command
, or
module
is given, Python enters interactive
mode, reading commands from stdin
(and using GNU readline, if installed, for input).
Besides using traditional command lines at a system shell prompt, you can also generally start Python programs by clicking their filenames in a file explorer GUI, by calling functions in the Python/C API, by using program launch menu options in IDEs such as IDLE, Komodo, Eclipse, NetBeans, and so on.
Python 2.6 does not support the -b
option, which is related to Python
3.0’s string type changes. It supports additional options:
-t
issues warnings for
inconsistent mixtures of tabs and spaces in indentation
(-tt
issues errors instead).
Python 3.0 always treats such mixtures as syntax errors.
-Q
division-related
options: -Qold
(the default),
-Qwarn
, -Qwarnall
, and –Qnew
. These are subsumed by the new
true division behavior of Python 3.0.
−3
issues warnings
about any Python 3.X incompatibilities in code.