Command-Line Options

% python [-diOSuvsxXt?]
 [-c command|filename| - ][arg*]
-d

Turn on parser debugging output (for wizards).

-i

Enter interactive mode after executing a script or command, without reading $PYTHONSTARTUP. Useful for postmortem debugging.

-O

Optimize generated byte-code.

-S

Don’t imply “import site” on initialization.

-u

Force stdout and stderr to be totally unbuffered.

-v

Print a message each time a module is initialized, showing the place from which it is loaded.

-s

Suppress printing of top-level expression results.

-x

Skip first line of source, allowing use of non-UNIX forms of #!cmd.

-X

Disable class-based built-in exceptions (for backward compatibility: forces string exceptions).

-t

Warn about mixed tabs and spaces in indentation.

-?

Print help message.

-c command

Specify a Python command (as a string) to execute.

filename

The name of a Python script file to execute.

-

Read Python commands from stdin (the default); enter interactive mode if stdin is a tty.

arg*

Anything else on the command line is passed to the script or command (and appears in list sys.argv[1:]).

Note

If no script or command, Python enters interactive mode (uses GNU readline for input if installed). Command-line options can be strung together or listed individually (e.g., “python -svd” is the same as “python -s -v -d”).

Get Python Pocket Reference 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.