blob: ef42c4ef94b04ce97e5bffb6913fd4e14af643cf [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[
Matthias Klosec8b16f82010-01-31 16:14:37 +000043.B \-s
44]
45[
Guido van Rossumb674baf2001-09-05 18:55:34 +000046.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000047]
48[
Guido van Rossumef5bca31994-05-03 14:15:32 +000049.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000050]
Guido van Rossumb674baf2001-09-05 18:55:34 +000051.br
52 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000053.B \-v
54]
Guido van Rossum07c44c71998-04-10 19:46:00 +000055[
Barry Warsaw64569372000-09-15 18:39:09 +000056.B \-V
57]
Guido van Rossum1378c322000-12-19 03:21:54 +000058[
59.B \-W
60.I argument
61]
Guido van Rossumb674baf2001-09-05 18:55:34 +000062[
63.B \-x
64]
Matthias Klosec8b16f82010-01-31 16:14:37 +000065[
66.B \-?
67]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000068.br
69 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000070.B \-c
71.I command
72|
73.I script
74|
75\-
76]
77[
78.I arguments
79]
80.SH DESCRIPTION
81Python is an interpreted, interactive, object-oriented programming
82language that combines remarkable power with very clear syntax.
83For an introduction to programming in Python you are referred to the
84Python Tutorial.
85The Python Library Reference documents built-in and standard types,
86constants, functions and modules.
87Finally, the Python Reference Manual describes the syntax and
88semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000089(These documents may be located via the
90.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000091below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000092.PP
93Python's basic power can be extended with your own modules written in
94C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000095On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000096Python is also adaptable as an extension language for existing
97applications.
98See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000099.PP
100Documentation for installed Python modules and packages can be
101viewed by running the
102.B pydoc
103program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000104.SH COMMAND LINE OPTIONS
105.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000106.B \-B
107Don't write
108.I .py[co]
109files on import. See also PYTHONDONTWRITEBYTECODE.
110.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000111.BI "\-c " command
112Specify the command to execute (see next section).
113This terminates the option list (following options are passed as
114arguments to the command).
115.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000116.B \-d
117Turn on parser debugging output (for wizards only, depending on
118compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000119.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000120.B \-E
121Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
122the behavior of the interpreter.
123.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000124.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000125Prints the usage for the interpreter executable and exits.
126.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000127.B \-i
128When a script is passed as first argument or the \fB\-c\fP option is
129used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000130command. It does not read the $PYTHONSTARTUP file. This can be
131useful to inspect global variables or a stack trace when a script
132raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000133.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000134.BI "\-m " module-name
135Searches
136.I sys.path
137for the named module and runs the corresponding
138.I .py
139file as a script.
140.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000141.B \-O
142Turn on basic optimizations. This changes the filename extension for
143compiled (bytecode) files from
144.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000145to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000146.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400147.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000148Discard docstrings in addition to the \fB-O\fP optimizations.
149.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000150.B \-q
151Do not print the version and copyright messages. These messages are
152also suppressed in non-interactive mode.
153.TP
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100154.B \-R
155Turn on "hash randomization", so that the hash() values of str, bytes and
156datetime objects are "salted" with an unpredictable pseudo-random value.
157Although they remain constant within an individual Python process, they are
158not predictable between repeated invocations of Python.
159.IP
160This is intended to provide protection against a denial of service
161caused by carefully-chosen inputs that exploit the worst case performance
162of a dict insertion, O(n^2) complexity. See
163http://www.ocert.org/advisories/ocert-2011-003.html
164for details.
165.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000166.B \-s
167Don't add user site directory to sys.path.
168.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000169.B \-S
170Disable the import of the module
171.I site
172and the site-dependent manipulations of
173.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100174that it entails. Also disable these manipulations if
175.I site
176is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000177.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000178.B \-u
Georg Brandl379299c2010-04-02 08:47:07 +0000179Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
180The text I/O layer will still be line-buffered.
181.\" Note that there is internal buffering in readlines() and
182.\" file-object iterators ("for line in sys.stdin") which is not
183.\" influenced by this option. To work around this, you will want to use
184.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000185.TP
186.B \-v
187Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000188(filename or built-in module) from which it is loaded. When given
189twice, print a message for each file that is checked for when
190searching for a module. Also provides information on module cleanup
191at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000192.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000193.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000194Prints the Python version number of the executable and exits.
195.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000196.BI "\-W " argument
197Warning control. Python sometimes prints warning message to
198.IR sys.stderr .
199A typical warning message has the following form:
200.IB file ":" line ": " category ": " message.
201By default, each warning is printed once for each source line where it
202occurs. This option controls how often warnings are printed.
203Multiple
204.B \-W
205options may be given; when a warning matches more than one
206option, the action for the last matching option is performed.
207Invalid
208.B \-W
209options are ignored (a warning message is printed about invalid
210options when the first warning is issued). Warnings can also be
211controlled from within a Python program using the
212.I warnings
213module.
214
215The simplest form of
216.I argument
217is one of the following
218.I action
219strings (or a unique abbreviation):
220.B ignore
221to ignore all warnings;
222.B default
223to explicitly request the default behavior (printing each warning once
224per source line);
225.B all
226to print a warning each time it occurs (this may generate many
227messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000228line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000229.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000230to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000231module;
232.B once
233to print each warning only the first time it occurs in the program; or
234.B error
235to raise an exception instead of printing a warning message.
236
237The full form of
238.I argument
239is
240.IB action : message : category : module : line.
241Here,
242.I action
243is as explained above but only applies to messages that match the
244remaining fields. Empty fields match all values; trailing empty
245fields may be omitted. The
246.I message
247field matches the start of the warning message printed; this match is
248case-insensitive. The
249.I category
250field matches the warning category. This must be a class name; the
251match test whether the actual warning category of the message is a
252subclass of the specified warning category. The full class name must
253be given. The
254.I module
255field matches the (fully-qualified) module name; this match is
256case-sensitive. The
257.I line
258field matches the line number, where zero matches all line numbers and
259is thus equivalent to an omitted line number.
260.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000261.B \-x
262Skip the first line of the source. This is intended for a DOS
263specific hack only. Warning: the line numbers in error messages will
264be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000265.SH INTERPRETER INTERFACE
266The interpreter interface resembles that of the UNIX shell: when
267called with standard input connected to a tty device, it prompts for
268commands and executes them until an EOF is read; when called with a
269file name argument or with a file as standard input, it reads and
270executes a
271.I script
272from that file;
273when called with
274.B \-c
275.I command,
276it executes the Python statement(s) given as
277.I command.
278Here
279.I command
280may contain multiple statements separated by newlines.
281Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000282In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000283executed.
284.PP
285If available, the script name and additional arguments thereafter are
286passed to the script in the Python variable
287.I sys.argv ,
288which is a list of strings (you must first
289.I import sys
290to be able to access it).
291If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000292.I sys.argv[0]
293is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000294.B \-c
295is used,
296.I sys.argv[0]
297contains the string
298.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000299Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000300are not placed in
301.I sys.argv.
302.PP
303In interactive mode, the primary prompt is `>>>'; the second prompt
304(which appears when a command is not complete) is `...'.
305The prompts can be changed by assignment to
306.I sys.ps1
307or
308.I sys.ps2.
309The interpreter quits when it reads an EOF at a prompt.
310When an unhandled exception occurs, a stack trace is printed and
311control returns to the primary prompt; in non-interactive mode, the
312interpreter exits after printing the stack trace.
313The interrupt signal raises the
314.I Keyboard\%Interrupt
315exception; other UNIX signals are not caught (except that SIGPIPE is
316sometimes ignored, in favor of the
317.I IOError
318exception). Error messages are written to stderr.
319.SH FILES AND DIRECTORIES
320These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000321conventions; ${prefix} and ${exec_prefix} are installation-dependent
322and should be interpreted as for GNU software; they may be the same.
323The default for both is \fI/usr/local\fP.
324.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000325Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000326.PP
327.I ${prefix}/lib/python<version>
328.br
329.I ${exec_prefix}/lib/python<version>
330.RS
331Recommended locations of the directories containing the standard
332modules.
333.RE
334.PP
335.I ${prefix}/include/python<version>
336.br
337.I ${exec_prefix}/include/python<version>
338.RS
339Recommended locations of the directories containing the include files
340needed for developing Python extensions and embedding the
341interpreter.
342.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000343.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000344.IP PYTHONHOME
345Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000346libraries are searched in ${prefix}/lib/python<version> and
347${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000348are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000349\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
350replaces both ${prefix} and ${exec_prefix}. To specify different values
351for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000352.IP PYTHONPATH
353Augments the default search path for module files.
354The format is the same as the shell's $PATH: one or more directory
355pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000356Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000357The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000358begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000359The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000360If a script argument is given, the directory containing the script is
361inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000362The search path can be manipulated from within a Python program as the
363variable
364.I sys.path .
365.IP PYTHONSTARTUP
366If this is the name of a readable file, the Python commands in that
367file are executed before the first prompt is displayed in interactive
368mode.
369The file is executed in the same name space where interactive commands
370are executed so that objects defined or imported in it can be used
371without qualification in the interactive session.
372You can also change the prompts
373.I sys.ps1
374and
375.I sys.ps2
376in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000377.IP PYTHONY2K
378Set this to a non-empty string to cause the \fItime\fP module to
379require dates specified as strings to include 4-digit years, otherwise
3802-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000381module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000382.IP PYTHONOPTIMIZE
383If this is set to a non-empty string it is equivalent to specifying
384the \fB\-O\fP option. If set to an integer, it is equivalent to
385specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000386.IP PYTHONDEBUG
387If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000388the \fB\-d\fP option. If set to an integer, it is equivalent to
389specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000390.IP PYTHONDONTWRITEBYTECODE
391If this is set to a non-empty string it is equivalent to specifying
392the \fB\-B\fP option (don't try to write
393.I .py[co]
394files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000395.IP PYTHONINSPECT
396If this is set to a non-empty string it is equivalent to specifying
397the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000398.IP PYTHONIOENCODING
399If this is set before running the interpreter, it overrides the encoding used
400for stdin/stdout/stderr, in the syntax
401.IB encodingname ":" errorhandler
402The
403.IB errorhandler
404part is optional and has the same meaning as in str.encode. For stderr, the
405.IB errorhandler
406 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000407.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000408If this is set to a non-empty string it is equivalent to specifying the
409\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000410.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000411If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000412the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000413.IP PYTHONVERBOSE
414If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000415the \fB\-v\fP option. If set to an integer, it is equivalent to
416specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000417.IP PYTHONWARNINGS
418If this is set to a comma-separated string it is equivalent to
419specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100420.IP PYTHONHASHSEED
421If this variable is set to "random", the effect is the same as specifying
422the \fB-R\fP option: a random value is used to seed the hashes of str,
423bytes and datetime objects.
424
425If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
426generating the hash() of the types covered by the hash randomization. Its
427purpose is to allow repeatable hashing, such as for selftests for the
428interpreter itself, or to allow a cluster of python processes to share hash
429values.
430
431The integer must be a decimal number in the range [0,4294967295]. Specifying
432the value 0 will lead to the same hash values as when hash randomization is
433disabled.
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.