blob: eacbc8dec4d79adedd3885302a148205868bc2e7 [file] [log] [blame]
Benjamin Peterson9b154902016-03-21 22:31:02 -07001.TH PYTHON "1"
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00002
Matthias Klose8ed25202009-03-22 13:08:22 +00003.\" To view this file while editing, run it through groff:
4.\" groff -Tascii -man python.man | less
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00005
Guido van Rossuma7925f11994-01-26 10:20:16 +00006.SH NAME
7python \- an interpreted, interactive, object-oriented programming language
8.SH SYNOPSIS
9.B python
10[
Matthias Klose626d92a2010-01-31 16:05:13 +000011.B \-B
12]
13[
Guido van Rossuma7925f11994-01-26 10:20:16 +000014.B \-d
15]
16[
Guido van Rossumb674baf2001-09-05 18:55:34 +000017.B \-E
18]
19[
20.B \-h
21]
22[
Guido van Rossuma7925f11994-01-26 10:20:16 +000023.B \-i
24]
25[
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000026.B \-m
27.I module-name
28]
Guido van Rossumb674baf2001-09-05 18:55:34 +000029.br
30 [
Matthias Klose626d92a2010-01-31 16:05:13 +000031.B \-O
32]
33[
R David Murrayf9860c82011-05-01 11:12:35 -040034.B \-OO
Matthias Klose626d92a2010-01-31 16:05:13 +000035]
36[
Barry Warsaw1e13eb02012-02-20 20:42:21 -050037.B \-R
38]
39[
Guido van Rossumb674baf2001-09-05 18:55:34 +000040.B -Q
41.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000042]
43[
Matthias Klose626d92a2010-01-31 16:05:13 +000044.B \-s
45]
46[
Guido van Rossumb674baf2001-09-05 18:55:34 +000047.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000048]
49[
Guido van Rossum29d465b1998-04-10 19:36:09 +000050.B \-t
51]
52[
Guido van Rossumef5bca31994-05-03 14:15:32 +000053.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000054]
Guido van Rossumb674baf2001-09-05 18:55:34 +000055.br
56 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000057.B \-v
58]
Guido van Rossum07c44c71998-04-10 19:46:00 +000059[
Barry Warsaw64569372000-09-15 18:39:09 +000060.B \-V
61]
Guido van Rossum1378c322000-12-19 03:21:54 +000062[
63.B \-W
64.I argument
65]
Guido van Rossumb674baf2001-09-05 18:55:34 +000066[
67.B \-x
68]
Benjamin Petersonc4431ee2009-01-09 03:05:14 +000069[
70.B \-3
71]
Matthias Klose626d92a2010-01-31 16:05:13 +000072[
73.B \-?
74]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000075.br
76 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000077.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.
Benjamin Peterson94e0f1e2015-04-29 18:00:44 -040090For an introduction to programming in Python, see the Python Tutorial.
Guido van Rossuma7925f11994-01-26 10:20:16 +000091The Python Library Reference documents built-in and standard types,
92constants, functions and modules.
93Finally, the Python Reference Manual describes the syntax and
94semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000095(These documents may be located via the
96.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000097below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000098.PP
99Python's basic power can be extended with your own modules written in
100C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +0000101On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000102Python is also adaptable as an extension language for existing
103applications.
104See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000105.PP
106Documentation for installed Python modules and packages can be
107viewed by running the
108.B pydoc
109program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000110.SH COMMAND LINE OPTIONS
111.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000112.B \-B
113Don't write
114.I .py[co]
115files on import. See also PYTHONDONTWRITEBYTECODE.
116.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000117.BI "\-c " command
118Specify the command to execute (see next section).
119This terminates the option list (following options are passed as
120arguments to the command).
121.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000122.B \-d
123Turn on parser debugging output (for wizards only, depending on
124compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000125.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000126.B \-E
127Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
128the behavior of the interpreter.
129.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000130.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000131Prints the usage for the interpreter executable and exits.
132.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000133.B \-i
134When a script is passed as first argument or the \fB\-c\fP option is
135used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000136command. It does not read the $PYTHONSTARTUP file. This can be
137useful to inspect global variables or a stack trace when a script
138raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000139.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000140.BI "\-m " module-name
141Searches
142.I sys.path
143for the named module and runs the corresponding
144.I .py
145file as a script.
146.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000147.B \-O
148Turn on basic optimizations. This changes the filename extension for
149compiled (bytecode) files from
150.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000151to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000152.TP
R David Murrayf9860c82011-05-01 11:12:35 -0400153.B \-OO
Matthias Klose626d92a2010-01-31 16:05:13 +0000154Discard docstrings in addition to the \fB-O\fP optimizations.
155.TP
Barry Warsaw1e13eb02012-02-20 20:42:21 -0500156.B \-R
157Turn on "hash randomization", so that the hash() values of str, bytes and
158datetime objects are "salted" with an unpredictable pseudo-random value.
159Although they remain constant within an individual Python process, they are
160not predictable between repeated invocations of Python.
161.IP
162This is intended to provide protection against a denial of service
163caused by carefully-chosen inputs that exploit the worst case performance
Georg Brandl3aec5682012-02-21 22:36:27 +0100164of a dict construction, O(n^2) complexity. See
Barry Warsaw1e13eb02012-02-20 20:42:21 -0500165http://www.ocert.org/advisories/ocert-2011-003.html
166for details.
167.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000168.BI "\-Q " argument
169Division control; see PEP 238. The argument must be one of "old" (the
170default, int/int and long/long return an int or long), "new" (new
171division semantics, i.e. int/int and long/long returns a float),
172"warn" (old division semantics with a warning for int/int and
173long/long), or "warnall" (old division semantics with a warning for
174all use of the division operator). For a use of "warnall", see the
175Tools/scripts/fixdiv.py script.
176.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000177.B \-s
178Don't add user site directory to sys.path.
179.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000180.B \-S
181Disable the import of the module
182.I site
183and the site-dependent manipulations of
184.I sys.path
185that it entails.
186.TP
Guido van Rossum29d465b1998-04-10 19:36:09 +0000187.B \-t
188Issue a warning when a source file mixes tabs and spaces for
189indentation in a way that makes it depend on the worth of a tab
190expressed in spaces. Issue an error when the option is given twice.
191.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000192.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000193Force stdin, stdout and stderr to be totally unbuffered. On systems
194where it matters, also put stdin, stdout and stderr in binary mode.
195Note that there is internal buffering in xreadlines(), readlines() and
196file-object iterators ("for line in sys.stdin") which is not
197influenced by this option. To work around this, you will want to use
198"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000199.TP
200.B \-v
201Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000202(filename or built-in module) from which it is loaded. When given
203twice, print a message for each file that is checked for when
204searching for a module. Also provides information on module cleanup
205at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000206.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000207.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000208Prints the Python version number of the executable and exits.
209.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000210.BI "\-W " argument
211Warning control. Python sometimes prints warning message to
212.IR sys.stderr .
213A typical warning message has the following form:
214.IB file ":" line ": " category ": " message.
215By default, each warning is printed once for each source line where it
216occurs. This option controls how often warnings are printed.
217Multiple
218.B \-W
219options may be given; when a warning matches more than one
220option, the action for the last matching option is performed.
221Invalid
222.B \-W
223options are ignored (a warning message is printed about invalid
224options when the first warning is issued). Warnings can also be
225controlled from within a Python program using the
226.I warnings
227module.
228
229The simplest form of
230.I argument
231is one of the following
232.I action
233strings (or a unique abbreviation):
234.B ignore
235to ignore all warnings;
236.B default
237to explicitly request the default behavior (printing each warning once
238per source line);
239.B all
240to print a warning each time it occurs (this may generate many
241messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000242line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000243.B module
Georg Brandl5a85d5c2009-06-24 06:41:19 +0000244to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000245module;
246.B once
247to print each warning only the first time it occurs in the program; or
248.B error
249to raise an exception instead of printing a warning message.
250
251The full form of
252.I argument
253is
254.IB action : message : category : module : line.
255Here,
256.I action
257is as explained above but only applies to messages that match the
258remaining fields. Empty fields match all values; trailing empty
259fields may be omitted. The
260.I message
261field matches the start of the warning message printed; this match is
262case-insensitive. The
263.I category
264field matches the warning category. This must be a class name; the
265match test whether the actual warning category of the message is a
266subclass of the specified warning category. The full class name must
267be given. The
268.I module
269field matches the (fully-qualified) module name; this match is
270case-sensitive. The
271.I line
272field matches the line number, where zero matches all line numbers and
273is thus equivalent to an omitted line number.
274.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000275.B \-x
276Skip the first line of the source. This is intended for a DOS
277specific hack only. Warning: the line numbers in error messages will
278be off by one!
Benjamin Petersonc4431ee2009-01-09 03:05:14 +0000279.TP
280.B \-3
281Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000282.SH INTERPRETER INTERFACE
283The interpreter interface resembles that of the UNIX shell: when
284called with standard input connected to a tty device, it prompts for
285commands and executes them until an EOF is read; when called with a
286file name argument or with a file as standard input, it reads and
287executes a
288.I script
289from that file;
290when called with
291.B \-c
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200292.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000293it executes the Python statement(s) given as
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200294.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000295Here
296.I command
297may contain multiple statements separated by newlines.
298Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000299In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000300executed.
301.PP
302If available, the script name and additional arguments thereafter are
303passed to the script in the Python variable
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200304.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000305which is a list of strings (you must first
306.I import sys
307to be able to access it).
308If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000309.I sys.argv[0]
310is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000311.B \-c
312is used,
313.I sys.argv[0]
314contains the string
315.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000316Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000317are not placed in
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200318.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000319.PP
320In interactive mode, the primary prompt is `>>>'; the second prompt
321(which appears when a command is not complete) is `...'.
322The prompts can be changed by assignment to
323.I sys.ps1
324or
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200325.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000326The interpreter quits when it reads an EOF at a prompt.
327When an unhandled exception occurs, a stack trace is printed and
328control returns to the primary prompt; in non-interactive mode, the
329interpreter exits after printing the stack trace.
330The interrupt signal raises the
331.I Keyboard\%Interrupt
332exception; other UNIX signals are not caught (except that SIGPIPE is
333sometimes ignored, in favor of the
334.I IOError
335exception). Error messages are written to stderr.
336.SH FILES AND DIRECTORIES
337These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000338conventions; ${prefix} and ${exec_prefix} are installation-dependent
339and should be interpreted as for GNU software; they may be the same.
340The default for both is \fI/usr/local\fP.
341.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000342Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000343.PP
344.I ${prefix}/lib/python<version>
345.br
346.I ${exec_prefix}/lib/python<version>
347.RS
348Recommended locations of the directories containing the standard
349modules.
350.RE
351.PP
352.I ${prefix}/include/python<version>
353.br
354.I ${exec_prefix}/include/python<version>
355.RS
356Recommended locations of the directories containing the include files
357needed for developing Python extensions and embedding the
358interpreter.
359.RE
360.IP \fI~/.pythonrc.py\fP
361User-specific initialization file loaded by the \fIuser\fP module;
362not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000363.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000364.IP PYTHONHOME
365Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000366libraries are searched in ${prefix}/lib/python<version> and
367${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000368are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000369\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
370replaces both ${prefix} and ${exec_prefix}. To specify different values
371for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000372.IP PYTHONPATH
373Augments the default search path for module files.
374The format is the same as the shell's $PATH: one or more directory
375pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000376Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000377The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000378begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000379The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000380If a script argument is given, the directory containing the script is
381inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000382The search path can be manipulated from within a Python program as the
383variable
doko@ubuntu.comd29d0392015-05-11 00:00:38 +0200384.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000385.IP PYTHONSTARTUP
386If this is the name of a readable file, the Python commands in that
387file are executed before the first prompt is displayed in interactive
388mode.
389The file is executed in the same name space where interactive commands
390are executed so that objects defined or imported in it can be used
391without qualification in the interactive session.
392You can also change the prompts
393.I sys.ps1
394and
395.I sys.ps2
396in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000397.IP PYTHONY2K
398Set this to a non-empty string to cause the \fItime\fP module to
399require dates specified as strings to include 4-digit years, otherwise
4002-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000401module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000402.IP PYTHONOPTIMIZE
403If this is set to a non-empty string it is equivalent to specifying
404the \fB\-O\fP option. If set to an integer, it is equivalent to
405specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000406.IP PYTHONDEBUG
407If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000408the \fB\-d\fP option. If set to an integer, it is equivalent to
409specifying \fB\-d\fP multiple times.
Matthias Klose626d92a2010-01-31 16:05:13 +0000410.IP PYTHONDONTWRITEBYTECODE
411If this is set to a non-empty string it is equivalent to specifying
412the \fB\-B\fP option (don't try to write
413.I .py[co]
414files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000415.IP PYTHONINSPECT
416If this is set to a non-empty string it is equivalent to specifying
417the \fB\-i\fP option.
Benjamin Petersona5cb39f2010-10-13 22:25:26 +0000418.IP PYTHONIOENCODING
419If this is set before running the interpreter, it overrides the encoding used
420for stdin/stdout/stderr, in the syntax
421.IB encodingname ":" errorhandler
422The
423.IB errorhandler
424part 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\'.
Matthias Klose626d92a2010-01-31 16:05:13 +0000427.IP PYTHONNOUSERSITE
Benjamin Petersona5cb39f2010-10-13 22:25:26 +0000428If 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).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000430.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000431If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000432the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000433.IP PYTHONVERBOSE
434If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000435the \fB\-v\fP option. If set to an integer, it is equivalent to
436specifying \fB\-v\fP multiple times.
Philip Jenvey5a5a37c2010-04-06 23:38:57 +0000437.IP PYTHONWARNINGS
438If this is set to a comma-separated string it is equivalent to
439specifying the \fB\-W\fP option for each separate value.
Barry Warsaw1e13eb02012-02-20 20:42:21 -0500440.IP PYTHONHASHSEED
441If this variable is set to "random", the effect is the same as specifying
442the \fB-R\fP option: a random value is used to seed the hashes of str,
443bytes and datetime objects.
444
445If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
446generating the hash() of the types covered by the hash randomization. Its
447purpose is to allow repeatable hashing, such as for selftests for the
448interpreter itself, or to allow a cluster of python processes to share hash
449values.
450
451The integer must be a decimal number in the range [0,4294967295]. Specifying
452the value 0 will lead to the same hash values as when hash randomization is
453disabled.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000454.SH AUTHOR
Benjamin Peterson42e268e2015-05-10 21:19:18 -0400455The Python Software Foundation: https://www.python.org/psf/
Guido van Rossum74faed21996-07-30 19:27:05 +0000456.SH INTERNET RESOURCES
Benjamin Peterson3a6b4812015-04-30 17:37:11 -0400457Main website: https://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000458.br
Benjamin Peterson3a6b4812015-04-30 17:37:11 -0400459Documentation: https://docs.python.org/2/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000460.br
Benjamin Peterson3a6b4812015-04-30 17:37:11 -0400461Developer resources: https://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000462.br
Benjamin Peterson3a6b4812015-04-30 17:37:11 -0400463Downloads: https://www.python.org/downloads/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000464.br
Benjamin Peterson3a6b4812015-04-30 17:37:11 -0400465Module repository: https://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000466.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000467Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000468.SH LICENSING
469Python is distributed under an Open Source license. See the file
470"LICENSE" in the Python source distribution for information on terms &
471conditions for accessing and otherwise using Python and for a
472DISCLAIMER OF ALL WARRANTIES.