Command-Line Options

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 | -c command | -m module | - ] [arg*]

Python Options

-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

Do not write .pyc or .pyo byte-code files on imports.

-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

Do not imply “import site” on initialization.

-u

Forces stdout and stderr to be unbuffered and binary.

-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

Prints Python version number and exit.

-W arg

Functions as warning control; arg takes the form action ...

Get Python Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.