blob: 20beded362773413e6a9c79b37eda60ce6f732d8 [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[
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]
Georg Brandl9d871192010-12-04 10:47:18 +000029[
30.B \-q
31]
Guido van Rossumb674baf2001-09-05 18:55:34 +000032.br
33 [
Matthias Klosec8b16f82010-01-31 16:14:37 +000034.B \-O
35]
36[
R David Murray9c4f09d2011-05-01 11:13:56 -040037.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +000038]
39[
Georg Brandl2daf6ae2012-02-20 19:54:16 +010040.B \-R
41]
42[
Guido van Rossumb674baf2001-09-05 18:55:34 +000043.B -Q
44.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000045]
46[
Matthias Klosec8b16f82010-01-31 16:14:37 +000047.B \-s
48]
49[
Guido van Rossumb674baf2001-09-05 18:55:34 +000050.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000051]
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]
Matthias Klosec8b16f82010-01-31 16:14:37 +000069[
70.B \-?
71]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000072.br
73 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000074.B \-c
75.I command
76|
77.I script
78|
79\-
80]
81[
82.I arguments
83]
84.SH DESCRIPTION
85Python is an interpreted, interactive, object-oriented programming
86language that combines remarkable power with very clear syntax.
87For an introduction to programming in Python you are referred to the
88Python Tutorial.
89The Python Library Reference documents built-in and standard types,
90constants, functions and modules.
91Finally, the Python Reference Manual describes the syntax and
92semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000093(These documents may be located via the
94.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000095below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000096.PP
97Python's basic power can be extended with your own modules written in
98C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000099On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000100Python is also adaptable as an extension language for existing
101applications.
102See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000103.PP
104Documentation for installed Python modules and packages can be
105viewed by running the
106.B pydoc
107program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000108.SH COMMAND LINE OPTIONS
109.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000110.B \-B
111Don't write
112.I .py[co]
113files on import. See also PYTHONDONTWRITEBYTECODE.
114.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000115.BI "\-c " command
116Specify the command to execute (see next section).
117This terminates the option list (following options are passed as
118arguments to the command).
119.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000120.B \-d
121Turn on parser debugging output (for wizards only, depending on
122compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000123.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000124.B \-E
125Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
126the behavior of the interpreter.
127.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000128.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000129Prints the usage for the interpreter executable and exits.
130.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000131.B \-i
132When a script is passed as first argument or the \fB\-c\fP option is
133used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000134command. It does not read the $PYTHONSTARTUP file. This can be
135useful to inspect global variables or a stack trace when a script
136raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000137.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000138.BI "\-m " module-name
139Searches
140.I sys.path
141for the named module and runs the corresponding
142.I .py
143file as a script.
144.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000145.B \-O
146Turn on basic optimizations. This changes the filename extension for
147compiled (bytecode) files from
148.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000149to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000150.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400151.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000152Discard docstrings in addition to the \fB-O\fP optimizations.
153.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000154.B \-q
155Do not print the version and copyright messages. These messages are
156also suppressed in non-interactive mode.
157.TP
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100158.B \-R
159Turn on "hash randomization", so that the hash() values of str, bytes and
160datetime objects are "salted" with an unpredictable pseudo-random value.
161Although they remain constant within an individual Python process, they are
162not predictable between repeated invocations of Python.
163.IP
164This is intended to provide protection against a denial of service
165caused by carefully-chosen inputs that exploit the worst case performance
Georg Brandlc9a42072012-02-21 22:36:27 +0100166of a dict construction, O(n^2) complexity. See
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100167http://www.ocert.org/advisories/ocert-2011-003.html
168for details.
169.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000170.BI "\-Q " argument
171Division control; see PEP 238. The argument must be one of "old" (the
172default, int/int and long/long return an int or long), "new" (new
173division semantics, i.e. int/int and long/long returns a float),
174"warn" (old division semantics with a warning for int/int and
175long/long), or "warnall" (old division semantics with a warning for
176all use of the division operator). For a use of "warnall", see the
177Tools/scripts/fixdiv.py script.
178.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000179.B \-s
180Don't add user site directory to sys.path.
181.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000182.B \-S
183Disable the import of the module
184.I site
185and the site-dependent manipulations of
186.I sys.path
187that it entails.
188.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000189.B \-u
Georg Brandl379299c2010-04-02 08:47:07 +0000190Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
191The text I/O layer will still be line-buffered.
192.\" Note that there is internal buffering in readlines() and
193.\" file-object iterators ("for line in sys.stdin") which is not
194.\" influenced by this option. To work around this, you will want to use
195.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000196.TP
197.B \-v
198Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000199(filename or built-in module) from which it is loaded. When given
200twice, print a message for each file that is checked for when
201searching for a module. Also provides information on module cleanup
202at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000203.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000204.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000205Prints the Python version number of the executable and exits.
206.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000207.BI "\-W " argument
208Warning control. Python sometimes prints warning message to
209.IR sys.stderr .
210A typical warning message has the following form:
211.IB file ":" line ": " category ": " message.
212By default, each warning is printed once for each source line where it
213occurs. This option controls how often warnings are printed.
214Multiple
215.B \-W
216options may be given; when a warning matches more than one
217option, the action for the last matching option is performed.
218Invalid
219.B \-W
220options are ignored (a warning message is printed about invalid
221options when the first warning is issued). Warnings can also be
222controlled from within a Python program using the
223.I warnings
224module.
225
226The simplest form of
227.I argument
228is one of the following
229.I action
230strings (or a unique abbreviation):
231.B ignore
232to ignore all warnings;
233.B default
234to explicitly request the default behavior (printing each warning once
235per source line);
236.B all
237to print a warning each time it occurs (this may generate many
238messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000239line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000240.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000241to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000242module;
243.B once
244to print each warning only the first time it occurs in the program; or
245.B error
246to raise an exception instead of printing a warning message.
247
248The full form of
249.I argument
250is
251.IB action : message : category : module : line.
252Here,
253.I action
254is as explained above but only applies to messages that match the
255remaining fields. Empty fields match all values; trailing empty
256fields may be omitted. The
257.I message
258field matches the start of the warning message printed; this match is
259case-insensitive. The
260.I category
261field matches the warning category. This must be a class name; the
262match test whether the actual warning category of the message is a
263subclass of the specified warning category. The full class name must
264be given. The
265.I module
266field matches the (fully-qualified) module name; this match is
267case-sensitive. The
268.I line
269field matches the line number, where zero matches all line numbers and
270is thus equivalent to an omitted line number.
271.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000272.B \-x
273Skip the first line of the source. This is intended for a DOS
274specific hack only. Warning: the line numbers in error messages will
275be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000276.SH INTERPRETER INTERFACE
277The interpreter interface resembles that of the UNIX shell: when
278called with standard input connected to a tty device, it prompts for
279commands and executes them until an EOF is read; when called with a
280file name argument or with a file as standard input, it reads and
281executes a
282.I script
283from that file;
284when called with
285.B \-c
286.I command,
287it executes the Python statement(s) given as
288.I command.
289Here
290.I command
291may contain multiple statements separated by newlines.
292Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000293In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000294executed.
295.PP
296If available, the script name and additional arguments thereafter are
297passed to the script in the Python variable
298.I sys.argv ,
299which is a list of strings (you must first
300.I import sys
301to be able to access it).
302If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000303.I sys.argv[0]
304is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000305.B \-c
306is used,
307.I sys.argv[0]
308contains the string
309.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000310Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000311are not placed in
312.I sys.argv.
313.PP
314In interactive mode, the primary prompt is `>>>'; the second prompt
315(which appears when a command is not complete) is `...'.
316The prompts can be changed by assignment to
317.I sys.ps1
318or
319.I sys.ps2.
320The interpreter quits when it reads an EOF at a prompt.
321When an unhandled exception occurs, a stack trace is printed and
322control returns to the primary prompt; in non-interactive mode, the
323interpreter exits after printing the stack trace.
324The interrupt signal raises the
325.I Keyboard\%Interrupt
326exception; other UNIX signals are not caught (except that SIGPIPE is
327sometimes ignored, in favor of the
328.I IOError
329exception). Error messages are written to stderr.
330.SH FILES AND DIRECTORIES
331These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000332conventions; ${prefix} and ${exec_prefix} are installation-dependent
333and should be interpreted as for GNU software; they may be the same.
334The default for both is \fI/usr/local\fP.
335.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000336Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000337.PP
338.I ${prefix}/lib/python<version>
339.br
340.I ${exec_prefix}/lib/python<version>
341.RS
342Recommended locations of the directories containing the standard
343modules.
344.RE
345.PP
346.I ${prefix}/include/python<version>
347.br
348.I ${exec_prefix}/include/python<version>
349.RS
350Recommended locations of the directories containing the include files
351needed for developing Python extensions and embedding the
352interpreter.
353.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000354.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000355.IP PYTHONHOME
356Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000357libraries are searched in ${prefix}/lib/python<version> and
358${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000359are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000360\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
361replaces both ${prefix} and ${exec_prefix}. To specify different values
362for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000363.IP PYTHONPATH
364Augments the default search path for module files.
365The format is the same as the shell's $PATH: one or more directory
366pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000367Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000368The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000369begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000370The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000371If a script argument is given, the directory containing the script is
372inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000373The search path can be manipulated from within a Python program as the
374variable
375.I sys.path .
376.IP PYTHONSTARTUP
377If this is the name of a readable file, the Python commands in that
378file are executed before the first prompt is displayed in interactive
379mode.
380The file is executed in the same name space where interactive commands
381are executed so that objects defined or imported in it can be used
382without qualification in the interactive session.
383You can also change the prompts
384.I sys.ps1
385and
386.I sys.ps2
387in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000388.IP PYTHONY2K
389Set this to a non-empty string to cause the \fItime\fP module to
390require dates specified as strings to include 4-digit years, otherwise
3912-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000392module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000393.IP PYTHONOPTIMIZE
394If this is set to a non-empty string it is equivalent to specifying
395the \fB\-O\fP option. If set to an integer, it is equivalent to
396specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000397.IP PYTHONDEBUG
398If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000399the \fB\-d\fP option. If set to an integer, it is equivalent to
400specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000401.IP PYTHONDONTWRITEBYTECODE
402If this is set to a non-empty string it is equivalent to specifying
403the \fB\-B\fP option (don't try to write
404.I .py[co]
405files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000406.IP PYTHONINSPECT
407If this is set to a non-empty string it is equivalent to specifying
408the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000409.IP PYTHONIOENCODING
410If this is set before running the interpreter, it overrides the encoding used
411for stdin/stdout/stderr, in the syntax
412.IB encodingname ":" errorhandler
413The
414.IB errorhandler
415part is optional and has the same meaning as in str.encode. For stderr, the
416.IB errorhandler
417 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000418.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000419If this is set to a non-empty string it is equivalent to specifying the
420\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000421.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000422If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000423the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000424.IP PYTHONVERBOSE
425If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000426the \fB\-v\fP option. If set to an integer, it is equivalent to
427specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000428.IP PYTHONWARNINGS
429If this is set to a comma-separated string it is equivalent to
430specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100431.IP PYTHONHASHSEED
432If this variable is set to "random", the effect is the same as specifying
433the \fB-R\fP option: a random value is used to seed the hashes of str,
434bytes and datetime objects.
435
436If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
437generating the hash() of the types covered by the hash randomization. Its
438purpose is to allow repeatable hashing, such as for selftests for the
439interpreter itself, or to allow a cluster of python processes to share hash
440values.
441
442The integer must be a decimal number in the range [0,4294967295]. Specifying
443the value 0 will lead to the same hash values as when hash randomization is
444disabled.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000445.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000446The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000447.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000448Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000449.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000450Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000451.br
Éric Araujoa2b89e32011-11-29 16:36:17 +0100452Developer resources: http://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000453.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000454Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000455.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000456Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000457.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000458Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000459.SH LICENSING
460Python is distributed under an Open Source license. See the file
461"LICENSE" in the Python source distribution for information on terms &
462conditions for accessing and otherwise using Python and for a
463DISCLAIMER OF ALL WARRANTIES.