blob: ea9540cd6468051db49aba064de333a8f46b2ff3 [file] [log] [blame]
Guido van Rossum97bac532001-09-05 18:57:51 +00001.TH PYTHON "1" "$Date$"
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00002
Benjamin Peterson5f28b7b2009-03-26 21:49:58 +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 Klosec8b16f82010-01-31 16:14:37 +000011.B \-B
12]
13[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050014.B \-b
15]
16[
Guido van Rossuma7925f11994-01-26 10:20:16 +000017.B \-d
18]
19[
Guido van Rossumb674baf2001-09-05 18:55:34 +000020.B \-E
21]
22[
23.B \-h
24]
25[
Guido van Rossuma7925f11994-01-26 10:20:16 +000026.B \-i
27]
28[
Christian Heimesad73a9c2013-08-10 16:36:18 +020029.B \-I
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000030]
Guido van Rossumb674baf2001-09-05 18:55:34 +000031.br
32 [
Christian Heimesad73a9c2013-08-10 16:36:18 +020033.B \-m
34.I module-name
35]
36[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050037.B \-q
38]
39[
Matthias Klosec8b16f82010-01-31 16:14:37 +000040.B \-O
41]
42[
R David Murray9c4f09d2011-05-01 11:13:56 -040043.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +000044]
45[
Matthias Klosec8b16f82010-01-31 16:14:37 +000046.B \-s
47]
48[
Guido van Rossumb674baf2001-09-05 18:55:34 +000049.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000050]
51[
Guido van Rossumef5bca31994-05-03 14:15:32 +000052.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000053]
Guido van Rossumb674baf2001-09-05 18:55:34 +000054.br
55 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000056.B \-v
57]
Guido van Rossum07c44c71998-04-10 19:46:00 +000058[
Barry Warsaw64569372000-09-15 18:39:09 +000059.B \-V
60]
Guido van Rossum1378c322000-12-19 03:21:54 +000061[
62.B \-W
63.I argument
64]
Guido van Rossumb674baf2001-09-05 18:55:34 +000065[
66.B \-x
67]
Matthias Klosec8b16f82010-01-31 16:14:37 +000068[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050069[
70.B \-X
71.I option
72]
Matthias Klosec8b16f82010-01-31 16:14:37 +000073.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 Petersonb0335ee2015-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 Klosec8b16f82010-01-31 16:14:37 +0000112.B \-B
113Don't write
114.I .py[co]
115files on import. See also PYTHONDONTWRITEBYTECODE.
116.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500117.B \-b
118Issue warnings about str(bytes_instance), str(bytearray_instance)
119and comparing bytes/bytearray with str. (-bb: issue errors)
120.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000121.BI "\-c " command
122Specify the command to execute (see next section).
123This terminates the option list (following options are passed as
124arguments to the command).
125.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000126.B \-d
127Turn on parser debugging output (for wizards only, depending on
128compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000129.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000130.B \-E
131Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
132the behavior of the interpreter.
133.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000134.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000135Prints the usage for the interpreter executable and exits.
136.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000137.B \-i
138When a script is passed as first argument or the \fB\-c\fP option is
139used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000140command. It does not read the $PYTHONSTARTUP file. This can be
141useful to inspect global variables or a stack trace when a script
142raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000143.TP
Christian Heimesad73a9c2013-08-10 16:36:18 +0200144.B \-I
Ned Deily64298ae2015-04-29 14:51:43 -0700145Run Python in isolated mode. This also implies \fB\-E\fP and \fB\-s\fP. In
Christian Heimesad73a9c2013-08-10 16:36:18 +0200146isolated mode sys.path contains neither the script’s directory nor the user’s
147site-packages directory. All PYTHON* environment variables are ignored, too.
148Further restrictions may be imposed to prevent the user from injecting
149malicious code.
150.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000151.BI "\-m " module-name
152Searches
153.I sys.path
154for the named module and runs the corresponding
155.I .py
156file as a script.
157.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000158.B \-O
159Turn on basic optimizations. This changes the filename extension for
160compiled (bytecode) files from
161.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000162to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000163.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400164.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000165Discard docstrings in addition to the \fB-O\fP optimizations.
166.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000167.B \-q
168Do not print the version and copyright messages. These messages are
169also suppressed in non-interactive mode.
170.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000171.B \-s
172Don't add user site directory to sys.path.
173.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000174.B \-S
175Disable the import of the module
176.I site
177and the site-dependent manipulations of
178.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100179that it entails. Also disable these manipulations if
180.I site
181is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000182.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000183.B \-u
Ezio Melotti61b0c672013-07-25 05:04:02 +0200184Force the binary I/O layers of stdout and stderr to be unbuffered.
185stdin is always buffered.
Georg Brandl379299c2010-04-02 08:47:07 +0000186The text I/O layer will still be line-buffered.
187.\" Note that there is internal buffering in readlines() and
188.\" file-object iterators ("for line in sys.stdin") which is not
189.\" influenced by this option. To work around this, you will want to use
190.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000191.TP
192.B \-v
193Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000194(filename or built-in module) from which it is loaded. When given
195twice, print a message for each file that is checked for when
196searching for a module. Also provides information on module cleanup
197at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000198.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000199.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000200Prints the Python version number of the executable and exits.
201.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000202.BI "\-W " argument
203Warning control. Python sometimes prints warning message to
204.IR sys.stderr .
205A typical warning message has the following form:
206.IB file ":" line ": " category ": " message.
207By default, each warning is printed once for each source line where it
208occurs. This option controls how often warnings are printed.
209Multiple
210.B \-W
211options may be given; when a warning matches more than one
212option, the action for the last matching option is performed.
213Invalid
214.B \-W
215options are ignored (a warning message is printed about invalid
216options when the first warning is issued). Warnings can also be
217controlled from within a Python program using the
218.I warnings
219module.
220
221The simplest form of
222.I argument
223is one of the following
224.I action
225strings (or a unique abbreviation):
226.B ignore
227to ignore all warnings;
228.B default
229to explicitly request the default behavior (printing each warning once
230per source line);
231.B all
232to print a warning each time it occurs (this may generate many
233messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000234line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000235.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000236to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000237module;
238.B once
239to print each warning only the first time it occurs in the program; or
240.B error
241to raise an exception instead of printing a warning message.
242
243The full form of
244.I argument
245is
246.IB action : message : category : module : line.
247Here,
248.I action
249is as explained above but only applies to messages that match the
250remaining fields. Empty fields match all values; trailing empty
251fields may be omitted. The
252.I message
253field matches the start of the warning message printed; this match is
254case-insensitive. The
255.I category
256field matches the warning category. This must be a class name; the
257match test whether the actual warning category of the message is a
258subclass of the specified warning category. The full class name must
259be given. The
260.I module
261field matches the (fully-qualified) module name; this match is
262case-sensitive. The
263.I line
264field matches the line number, where zero matches all line numbers and
265is thus equivalent to an omitted line number.
266.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500267.BI "\-X " option
268Set implementation specific option.
269.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000270.B \-x
271Skip the first line of the source. This is intended for a DOS
272specific hack only. Warning: the line numbers in error messages will
273be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000274.SH INTERPRETER INTERFACE
275The interpreter interface resembles that of the UNIX shell: when
276called with standard input connected to a tty device, it prompts for
277commands and executes them until an EOF is read; when called with a
278file name argument or with a file as standard input, it reads and
279executes a
280.I script
281from that file;
282when called with
283.B \-c
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200284.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000285it executes the Python statement(s) given as
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200286.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000287Here
288.I command
289may contain multiple statements separated by newlines.
290Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000291In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000292executed.
293.PP
294If available, the script name and additional arguments thereafter are
295passed to the script in the Python variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200296.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000297which is a list of strings (you must first
298.I import sys
299to be able to access it).
300If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000301.I sys.argv[0]
302is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000303.B \-c
304is used,
305.I sys.argv[0]
306contains the string
307.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000308Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000309are not placed in
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200310.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000311.PP
312In interactive mode, the primary prompt is `>>>'; the second prompt
313(which appears when a command is not complete) is `...'.
314The prompts can be changed by assignment to
315.I sys.ps1
316or
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200317.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000318The interpreter quits when it reads an EOF at a prompt.
319When an unhandled exception occurs, a stack trace is printed and
320control returns to the primary prompt; in non-interactive mode, the
321interpreter exits after printing the stack trace.
322The interrupt signal raises the
323.I Keyboard\%Interrupt
324exception; other UNIX signals are not caught (except that SIGPIPE is
325sometimes ignored, in favor of the
326.I IOError
327exception). Error messages are written to stderr.
328.SH FILES AND DIRECTORIES
329These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000330conventions; ${prefix} and ${exec_prefix} are installation-dependent
331and should be interpreted as for GNU software; they may be the same.
332The default for both is \fI/usr/local\fP.
333.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000334Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000335.PP
336.I ${prefix}/lib/python<version>
337.br
338.I ${exec_prefix}/lib/python<version>
339.RS
340Recommended locations of the directories containing the standard
341modules.
342.RE
343.PP
344.I ${prefix}/include/python<version>
345.br
346.I ${exec_prefix}/include/python<version>
347.RS
348Recommended locations of the directories containing the include files
349needed for developing Python extensions and embedding the
350interpreter.
351.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000352.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000353.IP PYTHONHOME
354Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000355libraries are searched in ${prefix}/lib/python<version> and
356${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000357are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000358\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
359replaces both ${prefix} and ${exec_prefix}. To specify different values
360for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000361.IP PYTHONPATH
362Augments the default search path for module files.
363The format is the same as the shell's $PATH: one or more directory
364pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000365Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000366The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000367begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000368The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000369If a script argument is given, the directory containing the script is
370inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000371The search path can be manipulated from within a Python program as the
372variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200373.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000374.IP PYTHONSTARTUP
375If this is the name of a readable file, the Python commands in that
376file are executed before the first prompt is displayed in interactive
377mode.
378The file is executed in the same name space where interactive commands
379are executed so that objects defined or imported in it can be used
380without qualification in the interactive session.
381You can also change the prompts
382.I sys.ps1
383and
384.I sys.ps2
385in this file.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000386.IP PYTHONOPTIMIZE
387If this is set to a non-empty string it is equivalent to specifying
388the \fB\-O\fP option. If set to an integer, it is equivalent to
389specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000390.IP PYTHONDEBUG
391If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000392the \fB\-d\fP option. If set to an integer, it is equivalent to
393specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000394.IP PYTHONDONTWRITEBYTECODE
395If this is set to a non-empty string it is equivalent to specifying
396the \fB\-B\fP option (don't try to write
397.I .py[co]
398files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000399.IP PYTHONINSPECT
400If this is set to a non-empty string it is equivalent to specifying
401the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000402.IP PYTHONIOENCODING
403If this is set before running the interpreter, it overrides the encoding used
404for stdin/stdout/stderr, in the syntax
405.IB encodingname ":" errorhandler
406The
407.IB errorhandler
408part is optional and has the same meaning as in str.encode. For stderr, the
409.IB errorhandler
410 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000411.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000412If this is set to a non-empty string it is equivalent to specifying the
413\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000414.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000415If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000416the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000417.IP PYTHONVERBOSE
418If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000419the \fB\-v\fP option. If set to an integer, it is equivalent to
420specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000421.IP PYTHONWARNINGS
422If this is set to a comma-separated string it is equivalent to
423specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100424.IP PYTHONHASHSEED
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500425If this variable is set to "random", a random value is used to seed the hashes
426of str, bytes and datetime objects.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100427
428If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
429generating the hash() of the types covered by the hash randomization. Its
430purpose is to allow repeatable hashing, such as for selftests for the
431interpreter itself, or to allow a cluster of python processes to share hash
432values.
433
434The integer must be a decimal number in the range [0,4294967295]. Specifying
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500435the value 0 will disable hash randomization.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000436.SH AUTHOR
Benjamin Peterson37c4f782015-05-10 21:19:18 -0400437The Python Software Foundation: https://www.python.org/psf/
Guido van Rossum74faed21996-07-30 19:27:05 +0000438.SH INTERNET RESOURCES
Benjamin Peterson755640b2015-04-30 17:37:11 -0400439Main website: https://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000440.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400441Documentation: https://docs.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000442.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400443Developer resources: https://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000444.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400445Downloads: https://www.python.org/downloads/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000446.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400447Module repository: https://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000448.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000449Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000450.SH LICENSING
451Python is distributed under an Open Source license. See the file
452"LICENSE" in the Python source distribution for information on terms &
453conditions for accessing and otherwise using Python and for a
454DISCLAIMER OF ALL WARRANTIES.