blob: 22d46e6859060d863856f6b772660be8b6116967 [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 Klose70924dd2010-01-31 16:17:23 +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 Klose70924dd2010-01-31 16:17:23 +000031.B \-O
32]
33[
R David Murray9c4f09d2011-05-01 11:13:56 -040034.B \-OO
Matthias Klose70924dd2010-01-31 16:17:23 +000035]
36[
Georg Brandl2daf6ae2012-02-20 19:54:16 +010037.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 Klose70924dd2010-01-31 16:17:23 +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 Rossumef5bca31994-05-03 14:15:32 +000050.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000051]
Guido van Rossumb674baf2001-09-05 18:55:34 +000052.br
53 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000054.B \-v
55]
Guido van Rossum07c44c71998-04-10 19:46:00 +000056[
Barry Warsaw64569372000-09-15 18:39:09 +000057.B \-V
58]
Guido van Rossum1378c322000-12-19 03:21:54 +000059[
60.B \-W
61.I argument
62]
Guido van Rossumb674baf2001-09-05 18:55:34 +000063[
64.B \-x
65]
Matthias Klose70924dd2010-01-31 16:17:23 +000066[
67.B \-?
68]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000069.br
70 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000071.B \-c
72.I command
73|
74.I script
75|
76\-
77]
78[
79.I arguments
80]
81.SH DESCRIPTION
82Python is an interpreted, interactive, object-oriented programming
83language that combines remarkable power with very clear syntax.
84For an introduction to programming in Python you are referred to the
85Python Tutorial.
86The Python Library Reference documents built-in and standard types,
87constants, functions and modules.
88Finally, the Python Reference Manual describes the syntax and
89semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000090(These documents may be located via the
91.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000092below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000093.PP
94Python's basic power can be extended with your own modules written in
95C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000096On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000097Python is also adaptable as an extension language for existing
98applications.
99See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000100.PP
101Documentation for installed Python modules and packages can be
102viewed by running the
103.B pydoc
104program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000105.SH COMMAND LINE OPTIONS
106.TP
Matthias Klose70924dd2010-01-31 16:17:23 +0000107.B \-B
108Don't write
109.I .py[co]
110files on import. See also PYTHONDONTWRITEBYTECODE.
111.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000112.BI "\-c " command
113Specify the command to execute (see next section).
114This terminates the option list (following options are passed as
115arguments to the command).
116.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000117.B \-d
118Turn on parser debugging output (for wizards only, depending on
119compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000120.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000121.B \-E
122Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
123the behavior of the interpreter.
124.TP
Matthias Klose70924dd2010-01-31 16:17:23 +0000125.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000126Prints the usage for the interpreter executable and exits.
127.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000128.B \-i
129When a script is passed as first argument or the \fB\-c\fP option is
130used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000131command. It does not read the $PYTHONSTARTUP file. This can be
132useful to inspect global variables or a stack trace when a script
133raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000134.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000135.BI "\-m " module-name
136Searches
137.I sys.path
138for the named module and runs the corresponding
139.I .py
140file as a script.
141.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000142.B \-O
143Turn on basic optimizations. This changes the filename extension for
144compiled (bytecode) files from
145.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000146to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000147.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400148.B \-OO
Matthias Klose70924dd2010-01-31 16:17:23 +0000149Discard docstrings in addition to the \fB-O\fP optimizations.
150.TP
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100151.B \-R
152Turn on "hash randomization", so that the hash() values of str, bytes and
153datetime objects are "salted" with an unpredictable pseudo-random value.
154Although they remain constant within an individual Python process, they are
155not predictable between repeated invocations of Python.
156.IP
157This is intended to provide protection against a denial of service
158caused by carefully-chosen inputs that exploit the worst case performance
Georg Brandlc9a42072012-02-21 22:36:27 +0100159of a dict construction, O(n^2) complexity. See
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100160http://www.ocert.org/advisories/ocert-2011-003.html
161for details.
162.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000163.BI "\-Q " argument
164Division control; see PEP 238. The argument must be one of "old" (the
165default, int/int and long/long return an int or long), "new" (new
166division semantics, i.e. int/int and long/long returns a float),
167"warn" (old division semantics with a warning for int/int and
168long/long), or "warnall" (old division semantics with a warning for
169all use of the division operator). For a use of "warnall", see the
170Tools/scripts/fixdiv.py script.
171.TP
Matthias Klose70924dd2010-01-31 16:17:23 +0000172.B \-s
173Don't add user site directory to sys.path.
174.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000175.B \-S
176Disable the import of the module
177.I site
178and the site-dependent manipulations of
179.I sys.path
180that it entails.
181.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000182.B \-u
Georg Brandl16215c72010-10-06 07:59:52 +0000183Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
184The 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
193twice, print a message for each file that is checked for when
194searching for a module. Also provides information on module cleanup
195at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000196.TP
Matthias Klose70924dd2010-01-31 16:17:23 +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
Guido van Rossumb674baf2001-09-05 18:55:34 +0000265.B \-x
266Skip the first line of the source. This is intended for a DOS
267specific hack only. Warning: the line numbers in error messages will
268be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000269.SH INTERPRETER INTERFACE
270The interpreter interface resembles that of the UNIX shell: when
271called with standard input connected to a tty device, it prompts for
272commands and executes them until an EOF is read; when called with a
273file name argument or with a file as standard input, it reads and
274executes a
275.I script
276from that file;
277when called with
278.B \-c
279.I command,
280it executes the Python statement(s) given as
281.I command.
282Here
283.I command
284may contain multiple statements separated by newlines.
285Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000286In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000287executed.
288.PP
289If available, the script name and additional arguments thereafter are
290passed to the script in the Python variable
291.I sys.argv ,
292which is a list of strings (you must first
293.I import sys
294to be able to access it).
295If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000296.I sys.argv[0]
297is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000298.B \-c
299is used,
300.I sys.argv[0]
301contains the string
302.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000303Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000304are not placed in
305.I sys.argv.
306.PP
307In interactive mode, the primary prompt is `>>>'; the second prompt
308(which appears when a command is not complete) is `...'.
309The prompts can be changed by assignment to
310.I sys.ps1
311or
312.I sys.ps2.
313The interpreter quits when it reads an EOF at a prompt.
314When an unhandled exception occurs, a stack trace is printed and
315control returns to the primary prompt; in non-interactive mode, the
316interpreter exits after printing the stack trace.
317The interrupt signal raises the
318.I Keyboard\%Interrupt
319exception; other UNIX signals are not caught (except that SIGPIPE is
320sometimes ignored, in favor of the
321.I IOError
322exception). Error messages are written to stderr.
323.SH FILES AND DIRECTORIES
324These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000325conventions; ${prefix} and ${exec_prefix} are installation-dependent
326and should be interpreted as for GNU software; they may be the same.
327The default for both is \fI/usr/local\fP.
328.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000329Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000330.PP
331.I ${prefix}/lib/python<version>
332.br
333.I ${exec_prefix}/lib/python<version>
334.RS
335Recommended locations of the directories containing the standard
336modules.
337.RE
338.PP
339.I ${prefix}/include/python<version>
340.br
341.I ${exec_prefix}/include/python<version>
342.RS
343Recommended locations of the directories containing the include files
344needed for developing Python extensions and embedding the
345interpreter.
346.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000347.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000348.IP PYTHONHOME
349Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000350libraries are searched in ${prefix}/lib/python<version> and
351${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000352are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000353\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
354replaces both ${prefix} and ${exec_prefix}. To specify different values
355for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356.IP PYTHONPATH
357Augments the default search path for module files.
358The format is the same as the shell's $PATH: one or more directory
359pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000360Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000361The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000362begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000363The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000364If a script argument is given, the directory containing the script is
365inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000366The search path can be manipulated from within a Python program as the
367variable
368.I sys.path .
369.IP PYTHONSTARTUP
370If this is the name of a readable file, the Python commands in that
371file are executed before the first prompt is displayed in interactive
372mode.
373The file is executed in the same name space where interactive commands
374are executed so that objects defined or imported in it can be used
375without qualification in the interactive session.
376You can also change the prompts
377.I sys.ps1
378and
379.I sys.ps2
380in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000381.IP PYTHONY2K
382Set this to a non-empty string to cause the \fItime\fP module to
383require dates specified as strings to include 4-digit years, otherwise
3842-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000385module documentation.
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 Klose70924dd2010-01-31 16:17:23 +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 Peterson2693d082010-10-13 22:23:03 +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 Klose70924dd2010-01-31 16:17:23 +0000411.IP PYTHONNOUSERSITE
Benjamin Peterson2693d082010-10-13 22:23:03 +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.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100421.IP PYTHONHASHSEED
422If this variable is set to "random", the effect is the same as specifying
423the \fB-R\fP option: a random value is used to seed the hashes of str,
424bytes and datetime objects.
425
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
433the value 0 will lead to the same hash values as when hash randomization is
434disabled.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000435.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000436The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000437.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000438Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000439.br
Benjamin Petersonb2f9e3b2009-09-13 02:29:37 +0000440Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000441.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000442Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000443.br
Benjamin Petersonb2f9e3b2009-09-13 02:29:37 +0000444Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000445.br
Benjamin Petersonb2f9e3b2009-09-13 02:29:37 +0000446Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000447.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000448Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000449.SH LICENSING
450Python is distributed under an Open Source license. See the file
451"LICENSE" in the Python source distribution for information on terms &
452conditions for accessing and otherwise using Python and for a
453DISCLAIMER OF ALL WARRANTIES.