blob: 8155e6a4472177abeaccc769b8e75aeddb528ed2 [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
Georg Brandl379299c2010-04-02 08:47:07 +0000175Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
176The text I/O layer will still be line-buffered.
177.\" Note that there is internal buffering in readlines() and
178.\" file-object iterators ("for line in sys.stdin") which is not
179.\" influenced by this option. To work around this, you will want to use
180.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000181.TP
182.B \-v
183Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000184(filename or built-in module) from which it is loaded. When given
185twice, print a message for each file that is checked for when
186searching for a module. Also provides information on module cleanup
187at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000188.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000189.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000190Prints the Python version number of the executable and exits.
191.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000192.BI "\-W " argument
193Warning control. Python sometimes prints warning message to
194.IR sys.stderr .
195A typical warning message has the following form:
196.IB file ":" line ": " category ": " message.
197By default, each warning is printed once for each source line where it
198occurs. This option controls how often warnings are printed.
199Multiple
200.B \-W
201options may be given; when a warning matches more than one
202option, the action for the last matching option is performed.
203Invalid
204.B \-W
205options are ignored (a warning message is printed about invalid
206options when the first warning is issued). Warnings can also be
207controlled from within a Python program using the
208.I warnings
209module.
210
211The simplest form of
212.I argument
213is one of the following
214.I action
215strings (or a unique abbreviation):
216.B ignore
217to ignore all warnings;
218.B default
219to explicitly request the default behavior (printing each warning once
220per source line);
221.B all
222to print a warning each time it occurs (this may generate many
223messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000224line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000225.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000226to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000227module;
228.B once
229to print each warning only the first time it occurs in the program; or
230.B error
231to raise an exception instead of printing a warning message.
232
233The full form of
234.I argument
235is
236.IB action : message : category : module : line.
237Here,
238.I action
239is as explained above but only applies to messages that match the
240remaining fields. Empty fields match all values; trailing empty
241fields may be omitted. The
242.I message
243field matches the start of the warning message printed; this match is
244case-insensitive. The
245.I category
246field matches the warning category. This must be a class name; the
247match test whether the actual warning category of the message is a
248subclass of the specified warning category. The full class name must
249be given. The
250.I module
251field matches the (fully-qualified) module name; this match is
252case-sensitive. The
253.I line
254field matches the line number, where zero matches all line numbers and
255is thus equivalent to an omitted line number.
256.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500257.BI "\-X " option
258Set implementation specific option.
259.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000260.B \-x
261Skip the first line of the source. This is intended for a DOS
262specific hack only. Warning: the line numbers in error messages will
263be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000264.SH INTERPRETER INTERFACE
265The interpreter interface resembles that of the UNIX shell: when
266called with standard input connected to a tty device, it prompts for
267commands and executes them until an EOF is read; when called with a
268file name argument or with a file as standard input, it reads and
269executes a
270.I script
271from that file;
272when called with
273.B \-c
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200274.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000275it executes the Python statement(s) given as
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200276.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000277Here
278.I command
279may contain multiple statements separated by newlines.
280Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000281In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000282executed.
283.PP
284If available, the script name and additional arguments thereafter are
285passed to the script in the Python variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200286.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000287which is a list of strings (you must first
288.I import sys
289to be able to access it).
290If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000291.I sys.argv[0]
292is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000293.B \-c
294is used,
295.I sys.argv[0]
296contains the string
297.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000298Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000299are not placed in
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200300.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000301.PP
302In interactive mode, the primary prompt is `>>>'; the second prompt
303(which appears when a command is not complete) is `...'.
304The prompts can be changed by assignment to
305.I sys.ps1
306or
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200307.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000308The interpreter quits when it reads an EOF at a prompt.
309When an unhandled exception occurs, a stack trace is printed and
310control returns to the primary prompt; in non-interactive mode, the
311interpreter exits after printing the stack trace.
312The interrupt signal raises the
313.I Keyboard\%Interrupt
314exception; other UNIX signals are not caught (except that SIGPIPE is
315sometimes ignored, in favor of the
316.I IOError
317exception). Error messages are written to stderr.
318.SH FILES AND DIRECTORIES
319These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000320conventions; ${prefix} and ${exec_prefix} are installation-dependent
321and should be interpreted as for GNU software; they may be the same.
322The default for both is \fI/usr/local\fP.
323.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000324Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000325.PP
326.I ${prefix}/lib/python<version>
327.br
328.I ${exec_prefix}/lib/python<version>
329.RS
330Recommended locations of the directories containing the standard
331modules.
332.RE
333.PP
334.I ${prefix}/include/python<version>
335.br
336.I ${exec_prefix}/include/python<version>
337.RS
338Recommended locations of the directories containing the include files
339needed for developing Python extensions and embedding the
340interpreter.
341.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000342.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000343.IP PYTHONHOME
344Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000345libraries are searched in ${prefix}/lib/python<version> and
346${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000347are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000348\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
349replaces both ${prefix} and ${exec_prefix}. To specify different values
350for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000351.IP PYTHONPATH
352Augments the default search path for module files.
353The format is the same as the shell's $PATH: one or more directory
354pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000355Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000356The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000357begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000358The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000359If a script argument is given, the directory containing the script is
360inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000361The search path can be manipulated from within a Python program as the
362variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200363.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000364.IP PYTHONSTARTUP
365If this is the name of a readable file, the Python commands in that
366file are executed before the first prompt is displayed in interactive
367mode.
368The file is executed in the same name space where interactive commands
369are executed so that objects defined or imported in it can be used
370without qualification in the interactive session.
371You can also change the prompts
372.I sys.ps1
373and
374.I sys.ps2
375in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000376.IP PYTHONY2K
377Set this to a non-empty string to cause the \fItime\fP module to
378require dates specified as strings to include 4-digit years, otherwise
3792-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000380module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000381.IP PYTHONOPTIMIZE
382If this is set to a non-empty string it is equivalent to specifying
383the \fB\-O\fP option. If set to an integer, it is equivalent to
384specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000385.IP PYTHONDEBUG
386If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000387the \fB\-d\fP option. If set to an integer, it is equivalent to
388specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000389.IP PYTHONDONTWRITEBYTECODE
390If this is set to a non-empty string it is equivalent to specifying
391the \fB\-B\fP option (don't try to write
392.I .py[co]
393files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000394.IP PYTHONINSPECT
395If this is set to a non-empty string it is equivalent to specifying
396the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000397.IP PYTHONIOENCODING
398If this is set before running the interpreter, it overrides the encoding used
399for stdin/stdout/stderr, in the syntax
400.IB encodingname ":" errorhandler
401The
402.IB errorhandler
403part is optional and has the same meaning as in str.encode. For stderr, the
404.IB errorhandler
405 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000406.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000407If this is set to a non-empty string it is equivalent to specifying the
408\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000409.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000410If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000411the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000412.IP PYTHONVERBOSE
413If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000414the \fB\-v\fP option. If set to an integer, it is equivalent to
415specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000416.IP PYTHONWARNINGS
417If this is set to a comma-separated string it is equivalent to
418specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100419.IP PYTHONHASHSEED
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500420If this variable is set to "random", a random value is used to seed the hashes
421of str, bytes and datetime objects.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100422
423If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
424generating the hash() of the types covered by the hash randomization. Its
425purpose is to allow repeatable hashing, such as for selftests for the
426interpreter itself, or to allow a cluster of python processes to share hash
427values.
428
429The integer must be a decimal number in the range [0,4294967295]. Specifying
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500430the value 0 will disable hash randomization.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000431.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000432The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000433.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000434Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000435.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000436Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000437.br
Éric Araujoa2b89e32011-11-29 16:36:17 +0100438Developer resources: http://docs.python.org/devguide/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000439.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000440Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000441.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000442Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000443.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000444Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000445.SH LICENSING
446Python is distributed under an Open Source license. See the file
447"LICENSE" in the Python source distribution for information on terms &
448conditions for accessing and otherwise using Python and for a
449DISCLAIMER OF ALL WARRANTIES.