blob: bcb3ec87233b63e3cce8f4f7b1ff481f6803f97d [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[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050029.B \-m
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000030.I module-name
31]
Guido van Rossumb674baf2001-09-05 18:55:34 +000032.br
33 [
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050034.B \-q
35]
36[
Matthias Klosec8b16f82010-01-31 16:14:37 +000037.B \-O
38]
39[
R David Murray9c4f09d2011-05-01 11:13:56 -040040.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +000041]
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[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050066[
67.B \-X
68.I option
69]
Matthias Klosec8b16f82010-01-31 16:14:37 +000070.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
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500115.B \-b
116Issue warnings about str(bytes_instance), str(bytearray_instance)
117and comparing bytes/bytearray with str. (-bb: issue errors)
118.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000119.BI "\-c " command
120Specify the command to execute (see next section).
121This terminates the option list (following options are passed as
122arguments to the command).
123.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000124.B \-d
125Turn on parser debugging output (for wizards only, depending on
126compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000127.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000128.B \-E
129Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
130the behavior of the interpreter.
131.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000132.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000133Prints the usage for the interpreter executable and exits.
134.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000135.B \-i
136When a script is passed as first argument or the \fB\-c\fP option is
137used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000138command. It does not read the $PYTHONSTARTUP file. This can be
139useful to inspect global variables or a stack trace when a script
140raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000141.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000142.BI "\-m " module-name
143Searches
144.I sys.path
145for the named module and runs the corresponding
146.I .py
147file as a script.
148.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000149.B \-O
150Turn on basic optimizations. This changes the filename extension for
151compiled (bytecode) files from
152.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000153to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000154.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400155.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000156Discard docstrings in addition to the \fB-O\fP optimizations.
157.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000158.B \-q
159Do not print the version and copyright messages. These messages are
160also suppressed in non-interactive mode.
161.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000162.B \-s
163Don't add user site directory to sys.path.
164.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000165.B \-S
166Disable the import of the module
167.I site
168and the site-dependent manipulations of
169.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100170that it entails. Also disable these manipulations if
171.I site
172is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000173.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000174.B \-u
Ezio Melotti61b0c672013-07-25 05:04:02 +0200175Force the binary I/O layers of stdout and stderr to be unbuffered.
176stdin is always buffered.
Georg Brandl379299c2010-04-02 08:47:07 +0000177The text I/O layer will still be line-buffered.
178.\" Note that there is internal buffering in readlines() and
179.\" file-object iterators ("for line in sys.stdin") which is not
180.\" influenced by this option. To work around this, you will want to use
181.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000182.TP
183.B \-v
184Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000185(filename or built-in module) from which it is loaded. When given
186twice, print a message for each file that is checked for when
187searching for a module. Also provides information on module cleanup
188at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000189.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000190.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000191Prints the Python version number of the executable and exits.
192.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000193.BI "\-W " argument
194Warning control. Python sometimes prints warning message to
195.IR sys.stderr .
196A typical warning message has the following form:
197.IB file ":" line ": " category ": " message.
198By default, each warning is printed once for each source line where it
199occurs. This option controls how often warnings are printed.
200Multiple
201.B \-W
202options may be given; when a warning matches more than one
203option, the action for the last matching option is performed.
204Invalid
205.B \-W
206options are ignored (a warning message is printed about invalid
207options when the first warning is issued). Warnings can also be
208controlled from within a Python program using the
209.I warnings
210module.
211
212The simplest form of
213.I argument
214is one of the following
215.I action
216strings (or a unique abbreviation):
217.B ignore
218to ignore all warnings;
219.B default
220to explicitly request the default behavior (printing each warning once
221per source line);
222.B all
223to print a warning each time it occurs (this may generate many
224messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000225line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000226.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000227to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000228module;
229.B once
230to print each warning only the first time it occurs in the program; or
231.B error
232to raise an exception instead of printing a warning message.
233
234The full form of
235.I argument
236is
237.IB action : message : category : module : line.
238Here,
239.I action
240is as explained above but only applies to messages that match the
241remaining fields. Empty fields match all values; trailing empty
242fields may be omitted. The
243.I message
244field matches the start of the warning message printed; this match is
245case-insensitive. The
246.I category
247field matches the warning category. This must be a class name; the
248match test whether the actual warning category of the message is a
249subclass of the specified warning category. The full class name must
250be given. The
251.I module
252field matches the (fully-qualified) module name; this match is
253case-sensitive. The
254.I line
255field matches the line number, where zero matches all line numbers and
256is thus equivalent to an omitted line number.
257.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500258.BI "\-X " option
259Set implementation specific option.
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
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200275.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000276it executes the Python statement(s) given as
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200277.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000278Here
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
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200287.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000288which 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
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200301.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000302.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
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200308.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000309The 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
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200364.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000365.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
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500421If this variable is set to "random", a random value is used to seed the hashes
422of str, bytes and datetime objects.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100423
424If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
425generating the hash() of the types covered by the hash randomization. Its
426purpose is to allow repeatable hashing, such as for selftests for the
427interpreter itself, or to allow a cluster of python processes to share hash
428values.
429
430The integer must be a decimal number in the range [0,4294967295]. Specifying
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500431the value 0 will disable hash randomization.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000432.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000433The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000434.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000435Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000436.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000437Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000438.br
Éric Araujoa2b89e32011-11-29 16:36:17 +0100439Developer resources: http://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000440.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000441Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000442.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000443Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000444.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000445Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000446.SH LICENSING
447Python is distributed under an Open Source license. See the file
448"LICENSE" in the Python source distribution for information on terms &
449conditions for accessing and otherwise using Python and for a
450DISCLAIMER OF ALL WARRANTIES.