blob: 1b37d0cd41f736bb5a3e6ae8e1b3638290f9af22 [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[
Matthias Klosec8b16f82010-01-31 16:14:37 +000040.B \-s
41]
42[
Guido van Rossumb674baf2001-09-05 18:55:34 +000043.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000044]
45[
Guido van Rossumef5bca31994-05-03 14:15:32 +000046.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000047]
Guido van Rossumb674baf2001-09-05 18:55:34 +000048.br
49 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000050.B \-v
51]
Guido van Rossum07c44c71998-04-10 19:46:00 +000052[
Barry Warsaw64569372000-09-15 18:39:09 +000053.B \-V
54]
Guido van Rossum1378c322000-12-19 03:21:54 +000055[
56.B \-W
57.I argument
58]
Guido van Rossumb674baf2001-09-05 18:55:34 +000059[
60.B \-x
61]
Matthias Klosec8b16f82010-01-31 16:14:37 +000062[
63.B \-?
64]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000065.br
66 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000067.B \-c
68.I command
69|
70.I script
71|
72\-
73]
74[
75.I arguments
76]
77.SH DESCRIPTION
78Python is an interpreted, interactive, object-oriented programming
79language that combines remarkable power with very clear syntax.
80For an introduction to programming in Python you are referred to the
81Python Tutorial.
82The Python Library Reference documents built-in and standard types,
83constants, functions and modules.
84Finally, the Python Reference Manual describes the syntax and
85semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000086(These documents may be located via the
87.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000088below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000089.PP
90Python's basic power can be extended with your own modules written in
91C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000092On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000093Python is also adaptable as an extension language for existing
94applications.
95See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000096.PP
97Documentation for installed Python modules and packages can be
98viewed by running the
99.B pydoc
100program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000101.SH COMMAND LINE OPTIONS
102.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000103.B \-B
104Don't write
105.I .py[co]
106files on import. See also PYTHONDONTWRITEBYTECODE.
107.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000108.BI "\-c " command
109Specify the command to execute (see next section).
110This terminates the option list (following options are passed as
111arguments to the command).
112.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000113.B \-d
114Turn on parser debugging output (for wizards only, depending on
115compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000116.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000117.B \-E
118Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
119the behavior of the interpreter.
120.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000121.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000122Prints the usage for the interpreter executable and exits.
123.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000124.B \-i
125When a script is passed as first argument or the \fB\-c\fP option is
126used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000127command. It does not read the $PYTHONSTARTUP file. This can be
128useful to inspect global variables or a stack trace when a script
129raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000130.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000131.BI "\-m " module-name
132Searches
133.I sys.path
134for the named module and runs the corresponding
135.I .py
136file as a script.
137.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000138.B \-O
139Turn on basic optimizations. This changes the filename extension for
140compiled (bytecode) files from
141.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000142to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000143.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400144.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000145Discard docstrings in addition to the \fB-O\fP optimizations.
146.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000147.B \-q
148Do not print the version and copyright messages. These messages are
149also suppressed in non-interactive mode.
150.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000151.B \-s
152Don't add user site directory to sys.path.
153.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000154.B \-S
155Disable the import of the module
156.I site
157and the site-dependent manipulations of
158.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100159that it entails. Also disable these manipulations if
160.I site
161is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000162.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000163.B \-u
Georg Brandl379299c2010-04-02 08:47:07 +0000164Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
165The text I/O layer will still be line-buffered.
166.\" Note that there is internal buffering in readlines() and
167.\" file-object iterators ("for line in sys.stdin") which is not
168.\" influenced by this option. To work around this, you will want to use
169.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000170.TP
171.B \-v
172Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000173(filename or built-in module) from which it is loaded. When given
174twice, print a message for each file that is checked for when
175searching for a module. Also provides information on module cleanup
176at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000177.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000178.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000179Prints the Python version number of the executable and exits.
180.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000181.BI "\-W " argument
182Warning control. Python sometimes prints warning message to
183.IR sys.stderr .
184A typical warning message has the following form:
185.IB file ":" line ": " category ": " message.
186By default, each warning is printed once for each source line where it
187occurs. This option controls how often warnings are printed.
188Multiple
189.B \-W
190options may be given; when a warning matches more than one
191option, the action for the last matching option is performed.
192Invalid
193.B \-W
194options are ignored (a warning message is printed about invalid
195options when the first warning is issued). Warnings can also be
196controlled from within a Python program using the
197.I warnings
198module.
199
200The simplest form of
201.I argument
202is one of the following
203.I action
204strings (or a unique abbreviation):
205.B ignore
206to ignore all warnings;
207.B default
208to explicitly request the default behavior (printing each warning once
209per source line);
210.B all
211to print a warning each time it occurs (this may generate many
212messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000213line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000214.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000215to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000216module;
217.B once
218to print each warning only the first time it occurs in the program; or
219.B error
220to raise an exception instead of printing a warning message.
221
222The full form of
223.I argument
224is
225.IB action : message : category : module : line.
226Here,
227.I action
228is as explained above but only applies to messages that match the
229remaining fields. Empty fields match all values; trailing empty
230fields may be omitted. The
231.I message
232field matches the start of the warning message printed; this match is
233case-insensitive. The
234.I category
235field matches the warning category. This must be a class name; the
236match test whether the actual warning category of the message is a
237subclass of the specified warning category. The full class name must
238be given. The
239.I module
240field matches the (fully-qualified) module name; this match is
241case-sensitive. The
242.I line
243field matches the line number, where zero matches all line numbers and
244is thus equivalent to an omitted line number.
245.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000246.B \-x
247Skip the first line of the source. This is intended for a DOS
248specific hack only. Warning: the line numbers in error messages will
249be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000250.SH INTERPRETER INTERFACE
251The interpreter interface resembles that of the UNIX shell: when
252called with standard input connected to a tty device, it prompts for
253commands and executes them until an EOF is read; when called with a
254file name argument or with a file as standard input, it reads and
255executes a
256.I script
257from that file;
258when called with
259.B \-c
260.I command,
261it executes the Python statement(s) given as
262.I command.
263Here
264.I command
265may contain multiple statements separated by newlines.
266Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000267In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000268executed.
269.PP
270If available, the script name and additional arguments thereafter are
271passed to the script in the Python variable
272.I sys.argv ,
273which is a list of strings (you must first
274.I import sys
275to be able to access it).
276If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000277.I sys.argv[0]
278is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000279.B \-c
280is used,
281.I sys.argv[0]
282contains the string
283.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000284Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000285are not placed in
286.I sys.argv.
287.PP
288In interactive mode, the primary prompt is `>>>'; the second prompt
289(which appears when a command is not complete) is `...'.
290The prompts can be changed by assignment to
291.I sys.ps1
292or
293.I sys.ps2.
294The interpreter quits when it reads an EOF at a prompt.
295When an unhandled exception occurs, a stack trace is printed and
296control returns to the primary prompt; in non-interactive mode, the
297interpreter exits after printing the stack trace.
298The interrupt signal raises the
299.I Keyboard\%Interrupt
300exception; other UNIX signals are not caught (except that SIGPIPE is
301sometimes ignored, in favor of the
302.I IOError
303exception). Error messages are written to stderr.
304.SH FILES AND DIRECTORIES
305These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000306conventions; ${prefix} and ${exec_prefix} are installation-dependent
307and should be interpreted as for GNU software; they may be the same.
308The default for both is \fI/usr/local\fP.
309.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000310Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000311.PP
312.I ${prefix}/lib/python<version>
313.br
314.I ${exec_prefix}/lib/python<version>
315.RS
316Recommended locations of the directories containing the standard
317modules.
318.RE
319.PP
320.I ${prefix}/include/python<version>
321.br
322.I ${exec_prefix}/include/python<version>
323.RS
324Recommended locations of the directories containing the include files
325needed for developing Python extensions and embedding the
326interpreter.
327.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000328.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000329.IP PYTHONHOME
330Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000331libraries are searched in ${prefix}/lib/python<version> and
332${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000333are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000334\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
335replaces both ${prefix} and ${exec_prefix}. To specify different values
336for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000337.IP PYTHONPATH
338Augments the default search path for module files.
339The format is the same as the shell's $PATH: one or more directory
340pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000341Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000342The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000343begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000344The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000345If a script argument is given, the directory containing the script is
346inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000347The search path can be manipulated from within a Python program as the
348variable
349.I sys.path .
350.IP PYTHONSTARTUP
351If this is the name of a readable file, the Python commands in that
352file are executed before the first prompt is displayed in interactive
353mode.
354The file is executed in the same name space where interactive commands
355are executed so that objects defined or imported in it can be used
356without qualification in the interactive session.
357You can also change the prompts
358.I sys.ps1
359and
360.I sys.ps2
361in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000362.IP PYTHONY2K
363Set this to a non-empty string to cause the \fItime\fP module to
364require dates specified as strings to include 4-digit years, otherwise
3652-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000366module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000367.IP PYTHONOPTIMIZE
368If this is set to a non-empty string it is equivalent to specifying
369the \fB\-O\fP option. If set to an integer, it is equivalent to
370specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000371.IP PYTHONDEBUG
372If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000373the \fB\-d\fP option. If set to an integer, it is equivalent to
374specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000375.IP PYTHONDONTWRITEBYTECODE
376If this is set to a non-empty string it is equivalent to specifying
377the \fB\-B\fP option (don't try to write
378.I .py[co]
379files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000380.IP PYTHONINSPECT
381If this is set to a non-empty string it is equivalent to specifying
382the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000383.IP PYTHONIOENCODING
384If this is set before running the interpreter, it overrides the encoding used
385for stdin/stdout/stderr, in the syntax
386.IB encodingname ":" errorhandler
387The
388.IB errorhandler
389part is optional and has the same meaning as in str.encode. For stderr, the
390.IB errorhandler
391 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000392.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000393If this is set to a non-empty string it is equivalent to specifying the
394\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000395.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000396If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000397the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000398.IP PYTHONVERBOSE
399If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000400the \fB\-v\fP option. If set to an integer, it is equivalent to
401specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000402.IP PYTHONWARNINGS
403If this is set to a comma-separated string it is equivalent to
404specifying the \fB\-W\fP option for each separate value.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000405.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000406The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000407.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000408Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000409.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000410Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000411.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000412Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000413.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000414Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000415.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000416Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000417.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000418Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000419.SH LICENSING
420Python is distributed under an Open Source license. See the file
421"LICENSE" in the Python source distribution for information on terms &
422conditions for accessing and otherwise using Python and for a
423DISCLAIMER OF ALL WARRANTIES.