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