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