| 1 |
.TH PYTHON "1" |
| 2 |
|
| 3 |
.\" To view this file while editing, run it through groff: |
| 4 |
.\" groff -Tascii -man python.man | less |
| 5 |
|
| 6 |
.SH NAME |
| 7 |
python \- an interpreted, interactive, object-oriented programming language |
| 8 |
.SH SYNOPSIS |
| 9 |
.B python |
| 10 |
[ |
| 11 |
.B \-B |
| 12 |
] |
| 13 |
[ |
| 14 |
.B \-d |
| 15 |
] |
| 16 |
[ |
| 17 |
.B \-E |
| 18 |
] |
| 19 |
[ |
| 20 |
.B \-h |
| 21 |
] |
| 22 |
[ |
| 23 |
.B \-i |
| 24 |
] |
| 25 |
[ |
| 26 |
.B \-m |
| 27 |
.I module-name |
| 28 |
] |
| 29 |
.br |
| 30 |
[ |
| 31 |
.B \-O |
| 32 |
] |
| 33 |
[ |
| 34 |
.B \-OO |
| 35 |
] |
| 36 |
[ |
| 37 |
.B \-R |
| 38 |
] |
| 39 |
[ |
| 40 |
.B -Q |
| 41 |
.I argument |
| 42 |
] |
| 43 |
[ |
| 44 |
.B \-s |
| 45 |
] |
| 46 |
[ |
| 47 |
.B \-S |
| 48 |
] |
| 49 |
[ |
| 50 |
.B \-t |
| 51 |
] |
| 52 |
[ |
| 53 |
.B \-u |
| 54 |
] |
| 55 |
.br |
| 56 |
[ |
| 57 |
.B \-v |
| 58 |
] |
| 59 |
[ |
| 60 |
.B \-V |
| 61 |
] |
| 62 |
[ |
| 63 |
.B \-W |
| 64 |
.I argument |
| 65 |
] |
| 66 |
[ |
| 67 |
.B \-x |
| 68 |
] |
| 69 |
[ |
| 70 |
.B \-3 |
| 71 |
] |
| 72 |
[ |
| 73 |
.B \-? |
| 74 |
] |
| 75 |
.br |
| 76 |
[ |
| 77 |
.B \-c |
| 78 |
.I command |
| 79 |
| |
| 80 |
.I script |
| 81 |
| |
| 82 |
\- |
| 83 |
] |
| 84 |
[ |
| 85 |
.I arguments |
| 86 |
] |
| 87 |
.SH DESCRIPTION |
| 88 |
Python is an interpreted, interactive, object-oriented programming |
| 89 |
language that combines remarkable power with very clear syntax. |
| 90 |
For an introduction to programming in Python, see the Python Tutorial. |
| 91 |
The Python Library Reference documents built-in and standard types, |
| 92 |
constants, functions and modules. |
| 93 |
Finally, the Python Reference Manual describes the syntax and |
| 94 |
semantics of the core language in (perhaps too) much detail. |
| 95 |
(These documents may be located via the |
| 96 |
.B "INTERNET RESOURCES" |
| 97 |
below; they may be installed on your system as well.) |
| 98 |
.PP |
| 99 |
Python's basic power can be extended with your own modules written in |
| 100 |
C or C++. |
| 101 |
On most systems such modules may be dynamically loaded. |
| 102 |
Python is also adaptable as an extension language for existing |
| 103 |
applications. |
| 104 |
See the internal documentation for hints. |
| 105 |
.PP |
| 106 |
Documentation for installed Python modules and packages can be |
| 107 |
viewed by running the |
| 108 |
.B pydoc |
| 109 |
program. |
| 110 |
.SH COMMAND LINE OPTIONS |
| 111 |
.TP |
| 112 |
.B \-B |
| 113 |
Don't write |
| 114 |
.I .py[co] |
| 115 |
files on import. See also PYTHONDONTWRITEBYTECODE. |
| 116 |
.TP |
| 117 |
.BI "\-c " command |
| 118 |
Specify the command to execute (see next section). |
| 119 |
This terminates the option list (following options are passed as |
| 120 |
arguments to the command). |
| 121 |
.TP |
| 122 |
.B \-d |
| 123 |
Turn on parser debugging output (for wizards only, depending on |
| 124 |
compilation options). |
| 125 |
.TP |
| 126 |
.B \-E |
| 127 |
Ignore environment variables like PYTHONPATH and PYTHONHOME that modify |
| 128 |
the behavior of the interpreter. |
| 129 |
.TP |
| 130 |
.B \-h ", " \-? ", "\-\-help |
| 131 |
Prints the usage for the interpreter executable and exits. |
| 132 |
.TP |
| 133 |
.B \-i |
| 134 |
When a script is passed as first argument or the \fB\-c\fP option is |
| 135 |
used, enter interactive mode after executing the script or the |
| 136 |
command. It does not read the $PYTHONSTARTUP file. This can be |
| 137 |
useful to inspect global variables or a stack trace when a script |
| 138 |
raises an exception. |
| 139 |
.TP |
| 140 |
.BI "\-m " module-name |
| 141 |
Searches |
| 142 |
.I sys.path |
| 143 |
for the named module and runs the corresponding |
| 144 |
.I .py |
| 145 |
file as a script. |
| 146 |
.TP |
| 147 |
.B \-O |
| 148 |
Turn on basic optimizations. This changes the filename extension for |
| 149 |
compiled (bytecode) files from |
| 150 |
.I .pyc |
| 151 |
to \fI.pyo\fP. Given twice, causes docstrings to be discarded. |
| 152 |
.TP |
| 153 |
.B \-OO |
| 154 |
Discard docstrings in addition to the \fB-O\fP optimizations. |
| 155 |
.TP |
| 156 |
.B \-R |
| 157 |
Turn on "hash randomization", so that the hash() values of str, bytes and |
| 158 |
datetime objects are "salted" with an unpredictable pseudo-random value. |
| 159 |
Although they remain constant within an individual Python process, they are |
| 160 |
not predictable between repeated invocations of Python. |
| 161 |
.IP |
| 162 |
This is intended to provide protection against a denial of service |
| 163 |
caused by carefully-chosen inputs that exploit the worst case performance |
| 164 |
of a dict construction, O(n^2) complexity. See |
| 165 |
http://www.ocert.org/advisories/ocert-2011-003.html |
| 166 |
for details. |
| 167 |
.TP |
| 168 |
.BI "\-Q " argument |
| 169 |
Division control; see PEP 238. The argument must be one of "old" (the |
| 170 |
default, int/int and long/long return an int or long), "new" (new |
| 171 |
division semantics, i.e. int/int and long/long returns a float), |
| 172 |
"warn" (old division semantics with a warning for int/int and |
| 173 |
long/long), or "warnall" (old division semantics with a warning for |
| 174 |
all use of the division operator). For a use of "warnall", see the |
| 175 |
Tools/scripts/fixdiv.py script. |
| 176 |
.TP |
| 177 |
.B \-s |
| 178 |
Don't add user site directory to sys.path. |
| 179 |
.TP |
| 180 |
.B \-S |
| 181 |
Disable the import of the module |
| 182 |
.I site |
| 183 |
and the site-dependent manipulations of |
| 184 |
.I sys.path |
| 185 |
that it entails. |
| 186 |
.TP |
| 187 |
.B \-t |
| 188 |
Issue a warning when a source file mixes tabs and spaces for |
| 189 |
indentation in a way that makes it depend on the worth of a tab |
| 190 |
expressed in spaces. Issue an error when the option is given twice. |
| 191 |
.TP |
| 192 |
.B \-u |
| 193 |
Force stdin, stdout and stderr to be totally unbuffered. On systems |
| 194 |
where it matters, also put stdin, stdout and stderr in binary mode. |
| 195 |
Note that there is internal buffering in xreadlines(), readlines() and |
| 196 |
file-object iterators ("for line in sys.stdin") which is not |
| 197 |
influenced by this option. To work around this, you will want to use |
| 198 |
"sys.stdin.readline()" inside a "while 1:" loop. |
| 199 |
.TP |
| 200 |
.B \-v |
| 201 |
Print a message each time a module is initialized, showing the place |
| 202 |
(filename or built-in module) from which it is loaded. When given |
| 203 |
twice, print a message for each file that is checked for when |
| 204 |
searching for a module. Also provides information on module cleanup |
| 205 |
at exit. |
| 206 |
.TP |
| 207 |
.B \-V ", " \-\-version |
| 208 |
Prints the Python version number of the executable and exits. |
| 209 |
.TP |
| 210 |
.BI "\-W " argument |
| 211 |
Warning control. Python sometimes prints warning message to |
| 212 |
.IR sys.stderr . |
| 213 |
A typical warning message has the following form: |
| 214 |
.IB file ":" line ": " category ": " message. |
| 215 |
By default, each warning is printed once for each source line where it |
| 216 |
occurs. This option controls how often warnings are printed. |
| 217 |
Multiple |
| 218 |
.B \-W |
| 219 |
options may be given; when a warning matches more than one |
| 220 |
option, the action for the last matching option is performed. |
| 221 |
Invalid |
| 222 |
.B \-W |
| 223 |
options are ignored (a warning message is printed about invalid |
| 224 |
options when the first warning is issued). Warnings can also be |
| 225 |
controlled from within a Python program using the |
| 226 |
.I warnings |
| 227 |
module. |
| 228 |
|
| 229 |
The simplest form of |
| 230 |
.I argument |
| 231 |
is one of the following |
| 232 |
.I action |
| 233 |
strings (or a unique abbreviation): |
| 234 |
.B ignore |
| 235 |
to ignore all warnings; |
| 236 |
.B default |
| 237 |
to explicitly request the default behavior (printing each warning once |
| 238 |
per source line); |
| 239 |
.B all |
| 240 |
to print a warning each time it occurs (this may generate many |
| 241 |
messages if a warning is triggered repeatedly for the same source |
| 242 |
line, such as inside a loop); |
| 243 |
.B module |
| 244 |
to print each warning only the first time it occurs in each |
| 245 |
module; |
| 246 |
.B once |
| 247 |
to print each warning only the first time it occurs in the program; or |
| 248 |
.B error |
| 249 |
to raise an exception instead of printing a warning message. |
| 250 |
|
| 251 |
The full form of |
| 252 |
.I argument |
| 253 |
is |
| 254 |
.IB action : message : category : module : line. |
| 255 |
Here, |
| 256 |
.I action |
| 257 |
is as explained above but only applies to messages that match the |
| 258 |
remaining fields. Empty fields match all values; trailing empty |
| 259 |
fields may be omitted. The |
| 260 |
.I message |
| 261 |
field matches the start of the warning message printed; this match is |
| 262 |
case-insensitive. The |
| 263 |
.I category |
| 264 |
field matches the warning category. This must be a class name; the |
| 265 |
match test whether the actual warning category of the message is a |
| 266 |
subclass of the specified warning category. The full class name must |
| 267 |
be given. The |
| 268 |
.I module |
| 269 |
field matches the (fully-qualified) module name; this match is |
| 270 |
case-sensitive. The |
| 271 |
.I line |
| 272 |
field matches the line number, where zero matches all line numbers and |
| 273 |
is thus equivalent to an omitted line number. |
| 274 |
.TP |
| 275 |
.B \-x |
| 276 |
Skip the first line of the source. This is intended for a DOS |
| 277 |
specific hack only. Warning: the line numbers in error messages will |
| 278 |
be off by one! |
| 279 |
.TP |
| 280 |
.B \-3 |
| 281 |
Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix. |
| 282 |
.SH INTERPRETER INTERFACE |
| 283 |
The interpreter interface resembles that of the UNIX shell: when |
| 284 |
called with standard input connected to a tty device, it prompts for |
| 285 |
commands and executes them until an EOF is read; when called with a |
| 286 |
file name argument or with a file as standard input, it reads and |
| 287 |
executes a |
| 288 |
.I script |
| 289 |
from that file; |
| 290 |
when called with |
| 291 |
.B \-c |
| 292 |
.IR command , |
| 293 |
it executes the Python statement(s) given as |
| 294 |
.IR command . |
| 295 |
Here |
| 296 |
.I command |
| 297 |
may contain multiple statements separated by newlines. |
| 298 |
Leading whitespace is significant in Python statements! |
| 299 |
In non-interactive mode, the entire input is parsed before it is |
| 300 |
executed. |
| 301 |
.PP |
| 302 |
If available, the script name and additional arguments thereafter are |
| 303 |
passed to the script in the Python variable |
| 304 |
.IR sys.argv , |
| 305 |
which is a list of strings (you must first |
| 306 |
.I import sys |
| 307 |
to be able to access it). |
| 308 |
If no script name is given, |
| 309 |
.I sys.argv[0] |
| 310 |
is an empty string; if |
| 311 |
.B \-c |
| 312 |
is used, |
| 313 |
.I sys.argv[0] |
| 314 |
contains the string |
| 315 |
.I '-c'. |
| 316 |
Note that options interpreted by the Python interpreter itself |
| 317 |
are not placed in |
| 318 |
.IR sys.argv . |
| 319 |
.PP |
| 320 |
In interactive mode, the primary prompt is `>>>'; the second prompt |
| 321 |
(which appears when a command is not complete) is `...'. |
| 322 |
The prompts can be changed by assignment to |
| 323 |
.I sys.ps1 |
| 324 |
or |
| 325 |
.IR sys.ps2 . |
| 326 |
The interpreter quits when it reads an EOF at a prompt. |
| 327 |
When an unhandled exception occurs, a stack trace is printed and |
| 328 |
control returns to the primary prompt; in non-interactive mode, the |
| 329 |
interpreter exits after printing the stack trace. |
| 330 |
The interrupt signal raises the |
| 331 |
.I Keyboard\%Interrupt |
| 332 |
exception; other UNIX signals are not caught (except that SIGPIPE is |
| 333 |
sometimes ignored, in favor of the |
| 334 |
.I IOError |
| 335 |
exception). Error messages are written to stderr. |
| 336 |
.SH FILES AND DIRECTORIES |
| 337 |
These are subject to difference depending on local installation |
| 338 |
conventions; ${prefix} and ${exec_prefix} are installation-dependent |
| 339 |
and should be interpreted as for GNU software; they may be the same. |
| 340 |
The default for both is \fI/usr/local\fP. |
| 341 |
.IP \fI${exec_prefix}/bin/python\fP |
| 342 |
Recommended location of the interpreter. |
| 343 |
.PP |
| 344 |
.I ${prefix}/lib/python<version> |
| 345 |
.br |
| 346 |
.I ${exec_prefix}/lib/python<version> |
| 347 |
.RS |
| 348 |
Recommended locations of the directories containing the standard |
| 349 |
modules. |
| 350 |
.RE |
| 351 |
.PP |
| 352 |
.I ${prefix}/include/python<version> |
| 353 |
.br |
| 354 |
.I ${exec_prefix}/include/python<version> |
| 355 |
.RS |
| 356 |
Recommended locations of the directories containing the include files |
| 357 |
needed for developing Python extensions and embedding the |
| 358 |
interpreter. |
| 359 |
.RE |
| 360 |
.IP \fI~/.pythonrc.py\fP |
| 361 |
User-specific initialization file loaded by the \fIuser\fP module; |
| 362 |
not used by default or by most applications. |
| 363 |
.SH ENVIRONMENT VARIABLES |
| 364 |
.IP PYTHONHOME |
| 365 |
Change the location of the standard Python libraries. By default, the |
| 366 |
libraries are searched in ${prefix}/lib/python<version> and |
| 367 |
${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix} |
| 368 |
are installation-dependent directories, both defaulting to |
| 369 |
\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value |
| 370 |
replaces both ${prefix} and ${exec_prefix}. To specify different values |
| 371 |
for these, set $PYTHONHOME to ${prefix}:${exec_prefix}. |
| 372 |
.IP PYTHONPATH |
| 373 |
Augments the default search path for module files. |
| 374 |
The format is the same as the shell's $PATH: one or more directory |
| 375 |
pathnames separated by colons. |
| 376 |
Non-existent directories are silently ignored. |
| 377 |
The default search path is installation dependent, but generally |
| 378 |
begins with ${prefix}/lib/python<version> (see PYTHONHOME above). |
| 379 |
The default search path is always appended to $PYTHONPATH. |
| 380 |
If a script argument is given, the directory containing the script is |
| 381 |
inserted in the path in front of $PYTHONPATH. |
| 382 |
The search path can be manipulated from within a Python program as the |
| 383 |
variable |
| 384 |
.IR sys.path . |
| 385 |
.IP PYTHONSTARTUP |
| 386 |
If this is the name of a readable file, the Python commands in that |
| 387 |
file are executed before the first prompt is displayed in interactive |
| 388 |
mode. |
| 389 |
The file is executed in the same name space where interactive commands |
| 390 |
are executed so that objects defined or imported in it can be used |
| 391 |
without qualification in the interactive session. |
| 392 |
You can also change the prompts |
| 393 |
.I sys.ps1 |
| 394 |
and |
| 395 |
.I sys.ps2 |
| 396 |
in this file. |
| 397 |
.IP PYTHONY2K |
| 398 |
Set this to a non-empty string to cause the \fItime\fP module to |
| 399 |
require dates specified as strings to include 4-digit years, otherwise |
| 400 |
2-digit years are converted based on rules described in the \fItime\fP |
| 401 |
module documentation. |
| 402 |
.IP PYTHONOPTIMIZE |
| 403 |
If this is set to a non-empty string it is equivalent to specifying |
| 404 |
the \fB\-O\fP option. If set to an integer, it is equivalent to |
| 405 |
specifying \fB\-O\fP multiple times. |
| 406 |
.IP PYTHONDEBUG |
| 407 |
If this is set to a non-empty string it is equivalent to specifying |
| 408 |
the \fB\-d\fP option. If set to an integer, it is equivalent to |
| 409 |
specifying \fB\-d\fP multiple times. |
| 410 |
.IP PYTHONDONTWRITEBYTECODE |
| 411 |
If this is set to a non-empty string it is equivalent to specifying |
| 412 |
the \fB\-B\fP option (don't try to write |
| 413 |
.I .py[co] |
| 414 |
files). |
| 415 |
.IP PYTHONINSPECT |
| 416 |
If this is set to a non-empty string it is equivalent to specifying |
| 417 |
the \fB\-i\fP option. |
| 418 |
.IP PYTHONIOENCODING |
| 419 |
If this is set before running the interpreter, it overrides the encoding used |
| 420 |
for stdin/stdout/stderr, in the syntax |
| 421 |
.IB encodingname ":" errorhandler |
| 422 |
The |
| 423 |
.IB errorhandler |
| 424 |
part is optional and has the same meaning as in str.encode. For stderr, the |
| 425 |
.IB errorhandler |
| 426 |
part is ignored; the handler will always be \'backslashreplace\'. |
| 427 |
.IP PYTHONNOUSERSITE |
| 428 |
If this is set to a non-empty string it is equivalent to specifying the |
| 429 |
\fB\-s\fP option (Don't add the user site directory to sys.path). |
| 430 |
.IP PYTHONUNBUFFERED |
| 431 |
If this is set to a non-empty string it is equivalent to specifying |
| 432 |
the \fB\-u\fP option. |
| 433 |
.IP PYTHONVERBOSE |
| 434 |
If this is set to a non-empty string it is equivalent to specifying |
| 435 |
the \fB\-v\fP option. If set to an integer, it is equivalent to |
| 436 |
specifying \fB\-v\fP multiple times. |
| 437 |
.IP PYTHONWARNINGS |
| 438 |
If this is set to a comma-separated string it is equivalent to |
| 439 |
specifying the \fB\-W\fP option for each separate value. |
| 440 |
.IP PYTHONHASHSEED |
| 441 |
If this variable is set to "random", the effect is the same as specifying |
| 442 |
the \fB-R\fP option: a random value is used to seed the hashes of str, |
| 443 |
bytes and datetime objects. |
| 444 |
|
| 445 |
If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for |
| 446 |
generating the hash() of the types covered by the hash randomization. Its |
| 447 |
purpose is to allow repeatable hashing, such as for selftests for the |
| 448 |
interpreter itself, or to allow a cluster of python processes to share hash |
| 449 |
values. |
| 450 |
|
| 451 |
The integer must be a decimal number in the range [0,4294967295]. Specifying |
| 452 |
the value 0 will lead to the same hash values as when hash randomization is |
| 453 |
disabled. |
| 454 |
.SH AUTHOR |
| 455 |
The Python Software Foundation: https://www.python.org/psf/ |
| 456 |
.SH INTERNET RESOURCES |
| 457 |
Main website: https://www.python.org/ |
| 458 |
.br |
| 459 |
Documentation: https://docs.python.org/2/ |
| 460 |
.br |
| 461 |
Developer resources: https://docs.python.org/devguide/ |
| 462 |
.br |
| 463 |
Downloads: https://www.python.org/downloads/ |
| 464 |
.br |
| 465 |
Module repository: https://pypi.python.org/ |
| 466 |
.br |
| 467 |
Newsgroups: comp.lang.python, comp.lang.python.announce |
| 468 |
.SH LICENSING |
| 469 |
Python is distributed under an Open Source license. See the file |
| 470 |
"LICENSE" in the Python source distribution for information on terms & |
| 471 |
conditions for accessing and otherwise using Python and for a |
| 472 |
DISCLAIMER OF ALL WARRANTIES. |