blob: fecd80241bd4c1d74704885f1fb9f589c8cfc5f4 [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.
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.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000096(These documents may be located via the
97.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000098below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000099.PP
100Python's basic power can be extended with your own modules written in
101C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +0000102On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000103Python is also adaptable as an extension language for existing
104applications.
105See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000106.PP
Brett Cannonf299abd2015-04-13 14:21:02 -0400107Documentation for installed Python modules and packages can be
108viewed by running the
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000109.B pydoc
Brett Cannonf299abd2015-04-13 14:21:02 -0400110program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000111.SH COMMAND LINE OPTIONS
112.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000113.B \-B
114Don't write
115.I .py[co]
116files on import. See also PYTHONDONTWRITEBYTECODE.
117.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500118.B \-b
119Issue warnings about str(bytes_instance), str(bytearray_instance)
120and comparing bytes/bytearray with str. (-bb: issue errors)
121.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000122.BI "\-c " command
123Specify the command to execute (see next section).
124This terminates the option list (following options are passed as
125arguments to the command).
126.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000127.B \-d
128Turn on parser debugging output (for wizards only, depending on
129compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000130.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000131.B \-E
132Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
133the behavior of the interpreter.
134.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000135.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000136Prints the usage for the interpreter executable and exits.
137.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000138.B \-i
139When a script is passed as first argument or the \fB\-c\fP option is
140used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000141command. It does not read the $PYTHONSTARTUP file. This can be
142useful to inspect global variables or a stack trace when a script
143raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000144.TP
Christian Heimesad73a9c2013-08-10 16:36:18 +0200145.B \-I
146Run Python in isolated mode. This also implies \fB\-E\fP and \fB\-S\fP. In
147isolated mode sys.path contains neither the script’s directory nor the user’s
148site-packages directory. All PYTHON* environment variables are ignored, too.
149Further restrictions may be imposed to prevent the user from injecting
150malicious code.
151.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000152.BI "\-m " module-name
Brett Cannonf299abd2015-04-13 14:21:02 -0400153Searches
154.I sys.path
155for the named module and runs the corresponding
156.I .py
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000157file as a script.
158.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000159.B \-O
Brett Cannonf299abd2015-04-13 14:21:02 -0400160Turn on basic optimizations. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000161.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400162.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000163Discard docstrings in addition to the \fB-O\fP optimizations.
164.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000165.B \-q
Brett Cannonf299abd2015-04-13 14:21:02 -0400166Do not print the version and copyright messages. These messages are
Georg Brandl9d871192010-12-04 10:47:18 +0000167also suppressed in non-interactive mode.
168.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000169.B \-s
170Don't add user site directory to sys.path.
171.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000172.B \-S
173Disable the import of the module
174.I site
175and the site-dependent manipulations of
176.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100177that it entails. Also disable these manipulations if
178.I site
179is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000180.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000181.B \-u
Ezio Melotti61b0c672013-07-25 05:04:02 +0200182Force the binary I/O layers of stdout and stderr to be unbuffered.
183stdin is always buffered.
Georg Brandl379299c2010-04-02 08:47:07 +0000184The text I/O layer will still be line-buffered.
185.\" Note that there is internal buffering in readlines() and
186.\" file-object iterators ("for line in sys.stdin") which is not
187.\" influenced by this option. To work around this, you will want to use
188.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000189.TP
190.B \-v
191Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000192(filename or built-in module) from which it is loaded. When given
Brett Cannonf299abd2015-04-13 14:21:02 -0400193twice, print a message for each file that is checked for when
Fred Drake4c9be9d1999-08-20 13:10:20 +0000194searching for a module. Also provides information on module cleanup
195at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000196.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000197.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000198Prints the Python version number of the executable and exits.
199.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000200.BI "\-W " argument
201Warning control. Python sometimes prints warning message to
202.IR sys.stderr .
203A typical warning message has the following form:
204.IB file ":" line ": " category ": " message.
205By default, each warning is printed once for each source line where it
206occurs. This option controls how often warnings are printed.
207Multiple
208.B \-W
209options may be given; when a warning matches more than one
210option, the action for the last matching option is performed.
211Invalid
212.B \-W
213options are ignored (a warning message is printed about invalid
214options when the first warning is issued). Warnings can also be
215controlled from within a Python program using the
216.I warnings
217module.
218
219The simplest form of
220.I argument
221is one of the following
222.I action
223strings (or a unique abbreviation):
224.B ignore
225to ignore all warnings;
226.B default
227to explicitly request the default behavior (printing each warning once
228per source line);
229.B all
230to print a warning each time it occurs (this may generate many
231messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000232line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000233.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000234to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000235module;
236.B once
237to print each warning only the first time it occurs in the program; or
238.B error
239to raise an exception instead of printing a warning message.
240
241The full form of
242.I argument
243is
244.IB action : message : category : module : line.
245Here,
246.I action
247is as explained above but only applies to messages that match the
248remaining fields. Empty fields match all values; trailing empty
249fields may be omitted. The
250.I message
251field matches the start of the warning message printed; this match is
252case-insensitive. The
253.I category
254field matches the warning category. This must be a class name; the
255match test whether the actual warning category of the message is a
256subclass of the specified warning category. The full class name must
257be given. The
258.I module
259field matches the (fully-qualified) module name; this match is
260case-sensitive. The
261.I line
262field matches the line number, where zero matches all line numbers and
263is thus equivalent to an omitted line number.
264.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500265.BI "\-X " option
266Set implementation specific option.
267.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000268.B \-x
269Skip the first line of the source. This is intended for a DOS
270specific hack only. Warning: the line numbers in error messages will
271be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000272.SH INTERPRETER INTERFACE
273The interpreter interface resembles that of the UNIX shell: when
274called with standard input connected to a tty device, it prompts for
275commands and executes them until an EOF is read; when called with a
276file name argument or with a file as standard input, it reads and
277executes a
278.I script
279from that file;
280when called with
281.B \-c
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200282.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000283it executes the Python statement(s) given as
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200284.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000285Here
286.I command
287may contain multiple statements separated by newlines.
288Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000289In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000290executed.
291.PP
292If available, the script name and additional arguments thereafter are
293passed to the script in the Python variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200294.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000295which is a list of strings (you must first
296.I import sys
297to be able to access it).
298If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000299.I sys.argv[0]
300is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000301.B \-c
302is used,
303.I sys.argv[0]
304contains the string
305.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000306Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000307are not placed in
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200308.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000309.PP
310In interactive mode, the primary prompt is `>>>'; the second prompt
311(which appears when a command is not complete) is `...'.
312The prompts can be changed by assignment to
313.I sys.ps1
314or
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200315.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000316The interpreter quits when it reads an EOF at a prompt.
317When an unhandled exception occurs, a stack trace is printed and
318control returns to the primary prompt; in non-interactive mode, the
319interpreter exits after printing the stack trace.
320The interrupt signal raises the
321.I Keyboard\%Interrupt
322exception; other UNIX signals are not caught (except that SIGPIPE is
323sometimes ignored, in favor of the
324.I IOError
325exception). Error messages are written to stderr.
326.SH FILES AND DIRECTORIES
327These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000328conventions; ${prefix} and ${exec_prefix} are installation-dependent
329and should be interpreted as for GNU software; they may be the same.
330The default for both is \fI/usr/local\fP.
331.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000332Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000333.PP
334.I ${prefix}/lib/python<version>
335.br
336.I ${exec_prefix}/lib/python<version>
337.RS
338Recommended locations of the directories containing the standard
339modules.
340.RE
341.PP
342.I ${prefix}/include/python<version>
343.br
344.I ${exec_prefix}/include/python<version>
345.RS
346Recommended locations of the directories containing the include files
347needed for developing Python extensions and embedding the
348interpreter.
349.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000350.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000351.IP PYTHONHOME
352Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000353libraries are searched in ${prefix}/lib/python<version> and
354${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000355are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000356\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
357replaces both ${prefix} and ${exec_prefix}. To specify different values
358for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000359.IP PYTHONPATH
360Augments the default search path for module files.
361The format is the same as the shell's $PATH: one or more directory
362pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000363Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000364The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000365begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000366The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000367If a script argument is given, the directory containing the script is
368inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000369The search path can be manipulated from within a Python program as the
370variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200371.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000372.IP PYTHONSTARTUP
373If this is the name of a readable file, the Python commands in that
374file are executed before the first prompt is displayed in interactive
375mode.
376The file is executed in the same name space where interactive commands
377are executed so that objects defined or imported in it can be used
378without qualification in the interactive session.
379You can also change the prompts
380.I sys.ps1
381and
382.I sys.ps2
383in this file.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000384.IP PYTHONOPTIMIZE
385If this is set to a non-empty string it is equivalent to specifying
386the \fB\-O\fP option. If set to an integer, it is equivalent to
387specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000388.IP PYTHONDEBUG
389If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000390the \fB\-d\fP option. If set to an integer, it is equivalent to
391specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000392.IP PYTHONDONTWRITEBYTECODE
393If this is set to a non-empty string it is equivalent to specifying
394the \fB\-B\fP option (don't try to write
395.I .py[co]
396files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000397.IP PYTHONINSPECT
398If this is set to a non-empty string it is equivalent to specifying
399the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000400.IP PYTHONIOENCODING
401If this is set before running the interpreter, it overrides the encoding used
402for stdin/stdout/stderr, in the syntax
403.IB encodingname ":" errorhandler
404The
405.IB errorhandler
406part is optional and has the same meaning as in str.encode. For stderr, the
407.IB errorhandler
408 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000409.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000410If this is set to a non-empty string it is equivalent to specifying the
411\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000412.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000413If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000414the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000415.IP PYTHONVERBOSE
416If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000417the \fB\-v\fP option. If set to an integer, it is equivalent to
Brett Cannonf299abd2015-04-13 14:21:02 -0400418specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000419.IP PYTHONWARNINGS
420If this is set to a comma-separated string it is equivalent to
421specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100422.IP PYTHONHASHSEED
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500423If this variable is set to "random", a random value is used to seed the hashes
424of str, bytes and datetime objects.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100425
426If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
427generating the hash() of the types covered by the hash randomization. Its
428purpose is to allow repeatable hashing, such as for selftests for the
429interpreter itself, or to allow a cluster of python processes to share hash
430values.
431
432The integer must be a decimal number in the range [0,4294967295]. Specifying
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500433the value 0 will disable hash randomization.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000434.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000435The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000436.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000437Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000438.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000439Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000440.br
Éric Araujoa2b89e32011-11-29 16:36:17 +0100441Developer resources: http://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000442.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000443Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000444.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000445Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000446.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000447Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000448.SH LICENSING
449Python is distributed under an Open Source license. See the file
450"LICENSE" in the Python source distribution for information on terms &
451conditions for accessing and otherwise using Python and for a
452DISCLAIMER OF ALL WARRANTIES.