python

interpreted, interactive, object-oriented programming language

python [-B] [-d] [-E] [-h] [-i] [-m module-name] [-O] [-OO] [-R] [-Q argument] [-s] [-S]
        [-t] [-u] [-v] [-V] [-W argument] [-x] [-3] [-? ] [-c command | script |-] [ arguments]

Command line options

-v Verbose output a message each time a module is initialized,
showing the place (filename or built-in module) from which it is loaded.
Given twice, outputs a message for each file that is checked for when searching for a module.
Also provides information on module cleanup at exit.
-c command Execute command.. Terminates the options with the remaining text passed as arguments to command.
-i WIth a script as the first argument or with -c, after executing the script or command, enter interactive mode.
Does not read $PYTHONSTARTUP .
Useful to inspect global variables or a stack trace when a script raises an exception.
-B Don't write .py[co] bytecode files on import. See $PYTHONDONTWRITEBYTECODE.
-E Ignore environment variables like $PYTHONPATH and $PYTHONHOME that modify the behavior
-m module-name runs sys.path module-name
-O Turn on basic optimizations. Uses .pyo for the filename extension for compiled (bytecode) files .
Given twice, causes docstrings to be discarded.
-OO Discard docstrings and optimizations.
-R Turn on "hash randomization", so that the hash() values of str, bytes and datetime objects are "salted" with an unpredictable pseudo-random value which is constant within an individual Python process,
They are not predictable between invocations of Python.
-Q argument Division control; see PEP 238.
"old" (the default, int/int and long/long return an int or long),
"new" (new division semantics, i.e. int/int and long/long returns a float)
"warn" (old division semantics with a warning for int/int and long/long)
"warnall" (old division semantics with a warning for all use of the division operator). see Tools/scripts/fixdiv.py .
-s Don't add user site directory to sys.path.
-S Disable import of site and the site-dependent manipulations of sys.path
-t Warn if source mixes tabs and spaces for indentation in a way that makes it depend on the number spaces for a tab.
-u stdin, stdout and stderr are unbuffered , binary mode.
xreadlines(), readlines() and file-object iterators ("for line in sys.stdin") are unaffected.
. To avoid this, to use sys.stdin.readline() inside a while 1: loop.
-V
--version
outputs the version number and exits.
-h
-?
--help
Outputs the usage for the interpreter executable and exits.
-W argument Warning control. Multiple -W may be given;
By default, each warning is output once for each source line where it occurs. Sometimes warning message are output to sys.stderr.
A typical warning message has the form: file:line: category: message.
When a warning matches more than one option, the action for the last matching option is performed.
Invalid options are ignored (a warning message is output about invalid options when the first warning is issued). Warnings can also be controlled from within a Python program using the warnings module.

The simplest form of argument is an action string (or a unique abbreviation):

ignore ignore all warnings;
default explicitly request the default behavior (outputing each warning once per source line);
all output a warning each time it occurs (this may generate many messages if a warning is triggered repeatedly for the same source line, such as inside a loop);
module output each warning only the first time it occurs in each module;
once output each warning only the first time it occurs in the program; or
error raise an exception instead of outputting a message.

The full form of argument is
action:message:category:module:[line].

message is a case-insensitive match of the start of the warning message.
category matches the warning category; a class name. The match tests whether the actual warning category of the message is a subclass of the specified warning category. The full class name must be given.
module is a case-sensitive match of the fully-qualified module name.
line Omitting or using 0 matches all
Empty fields match all values; trailing empty fields may be omitted.
-3 Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.

INTERPRETER INTERFACE

When called with standard input connected to a tty device, interactively prompts for commands and executes them until quit() or EOF .
When called with a file name argument or with a file as standard input, reads and executes a script from that file.
when called with -c command, executes statement(s) . separated by newlines.
Leading whitespace is significant
In non-interactive mode, the entire input is parsed before it is executed.

After import sys, the script name and arguments are passed to the script in sys.argv, a list of strings .
If no script name is given, sys.argv[0] is an empty string;
if -c is used, sys.argv[0] contains the string '-c'.
Options interpreted by the Python interpreter are not placed in sys.argv.

In interactive mode, the primary prompt is >>>; the second prompt (i.e continuation ) is ....
which can be changed by assignment to sys.ps1 or sys.ps2.

When an unhandled exception occurs, a stack trace is output. In non-interactive mode the interpreter exits
Interactively control returns to the primary prompt. The interrupt signal raises the KeyboardInterrupt exception; other signals are not caught (SIGPIPE is sometimes ignored, in favor of the IOError exception).
Error messages are written to stderr.

Files and Directories

Depend on installation ${prefix} and ${exec_prefix} are installation-dependent. The default for both is /usr/local. On mac os they are /usr/local/bin

Recommended location of the interpreter.: ${exec_prefix}/bin/python

Recommended locations of the directories containing the standard modules:
${prefix}/lib/pythonversion
${exec_prefix}/lib/pythonversion

Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter.:
${prefix}/include/pythonversion
${exec_prefix}/include/pythonversion

User-specific initialization file loaded by the user module; not used by default or by most applications. ~/.pythonrc.py

Environment Variables

$PYTHONHOME
Location of the standard Python libraries. By default, ${prefix}/lib/pythonversion and ${exec_prefix}/lib/pythonversion, where ${prefix} and ${exec_prefix} are installation-dependent directories, both defaulting to /usr/local.
When $PYTHONHOME is a single directory, its value replaces both ${prefix} and ${exec_prefix}. To specify different values for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.

$PYTHONPATH Prepended to the default search path for module files. The format is one or more directory pathnames separated by colons. Non-existent directories are silently ignored.
The default search path is installation dependent, the recommendataion begins with ${prefix}/lib/pythonversion (see PYTHONHOME ). With an script argument the directory containing the script is inserted in the path in before $PYTHONPATH. The search path can be manipulated in a program as the variable sys.path.

$PYTHONSTARTUP Executed before the first prompt is displayed in interactive mode. The file is executed in the same name space where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session. You can also change the prompts sys.ps1 and sys.ps2 in this file.

$PYTHONY2K Set to a non-empty string to causes the time module to require dates specified as strings to include 4-digit years, otherwise 2-digit years are converted based on rules described in the time module documentation.

$PYTHONOPTIMIZE A non-empty string equivalent to specifying -O . If an integer, it is equivalent to specifying -O multiple times.

$PYTHONDEBUG a non-empty string is equivalent to -d . If an integer, equivalent to specifying -d multiple times.

$PYTHONDONTWRITEBYTECODE a non-empty string is equivalent to specifying -B (don't write .py[co] files).

$PYTHONINSPECT a non-empty string is equivalent to specifying -i .

$PYTHONIOENCODING overrides the encoding used for stdin/stdout/stderr, in the syntax encodingname:[errorhandler] errorhandler has the same meaning as in str.encode. For stderr, the errorhandler is ignored; the handler will always be 'backslashreplace'.

$PYTHONNOUSERSITE a non-empty string is equivalent to -s (Don't add the user site directory to sys.path).

$PYTHONUNBUFFERED a non-empty string it is equivalent to specifying -u (unbuffered) .

$PYTHONVERBOSE If this is set to a non-empty string it is equivalent to specifying the -v option. If set to an integer, it is equivalent to specifying -v multiple times.

$PYTHONWARNINGS A comma-separated string is equivalent to -W

$PYTHONHASHSEED random is the same as -R : a random value is used to seed the hashes of str, bytes and datetime objects.
$PYTHONHASHSEED is used as a fixed integer seed (0,4294967295) for generating the hash() of the types covered by hash randomization. This allows repeatable hashing, such as for selftests for the interpreter itself, or to allow a cluster of python processes to share hash values. 0 will lead to the same hash values as when hash randomization is disabled.

Interactive Input Editing and History Substitution

The readline module provides the access to the EditLine library
The command language used in the preference files is that of EditLine, as described in editrc(5) .
parse_and_bind() use EditLine commands. the preference file is ~/.editrc.

The rlcompleter module, which defines a completion function for the readline modules, works with the EditLine libraries, needs to be initialized using:
import rlcompleter
import readline
readline.parse_and_bind("bind ^I rl_complete")

For vi mode: readline.parse_and_bind("bind -v")

AUTHOR

The Python Software Foundation: Pythoin.org

INTERNET RESOURCES

Main website: https://www.python.org/
Documentation: https://docs.python.org/2/
Developer resources: https://docs.python.org/devguide/
Downloads: https://www.python.org/downloads/
Module repository: https://pypi.python.org/
Newsgroups: comp.lang.python, comp.lang.python.announce