blob: 0921e4c0c4d806ab300bfea2635c38f4561d019c [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[
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 Klosec8b16f82010-01-31 16:14:37 +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 Klosec8b16f82010-01-31 16:14:37 +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 Klosec8b16f82010-01-31 16:14:37 +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 Klosec8b16f82010-01-31 16:14:37 +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 Klosec8b16f82010-01-31 16:14:37 +0000149Discard docstrings in addition to the \fB-O\fP optimizations.
150.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000151.B \-q
152Do not print the version and copyright messages. These messages are
153also suppressed in non-interactive mode.
154.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000155.BI "\-Q " argument
156Division control; see PEP 238. The argument must be one of "old" (the
157default, int/int and long/long return an int or long), "new" (new
158division semantics, i.e. int/int and long/long returns a float),
159"warn" (old division semantics with a warning for int/int and
160long/long), or "warnall" (old division semantics with a warning for
161all use of the division operator). For a use of "warnall", see the
162Tools/scripts/fixdiv.py script.
163.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000164.B \-s
165Don't add user site directory to sys.path.
166.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000167.B \-S
168Disable the import of the module
169.I site
170and the site-dependent manipulations of
171.I sys.path
172that it entails.
173.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
Guido van Rossumb674baf2001-09-05 18:55:34 +0000257.B \-x
258Skip the first line of the source. This is intended for a DOS
259specific hack only. Warning: the line numbers in error messages will
260be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000261.SH INTERPRETER INTERFACE
262The interpreter interface resembles that of the UNIX shell: when
263called with standard input connected to a tty device, it prompts for
264commands and executes them until an EOF is read; when called with a
265file name argument or with a file as standard input, it reads and
266executes a
267.I script
268from that file;
269when called with
270.B \-c
271.I command,
272it executes the Python statement(s) given as
273.I command.
274Here
275.I command
276may contain multiple statements separated by newlines.
277Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000278In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000279executed.
280.PP
281If available, the script name and additional arguments thereafter are
282passed to the script in the Python variable
283.I sys.argv ,
284which is a list of strings (you must first
285.I import sys
286to be able to access it).
287If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000288.I sys.argv[0]
289is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000290.B \-c
291is used,
292.I sys.argv[0]
293contains the string
294.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000295Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000296are not placed in
297.I sys.argv.
298.PP
299In interactive mode, the primary prompt is `>>>'; the second prompt
300(which appears when a command is not complete) is `...'.
301The prompts can be changed by assignment to
302.I sys.ps1
303or
304.I sys.ps2.
305The interpreter quits when it reads an EOF at a prompt.
306When an unhandled exception occurs, a stack trace is printed and
307control returns to the primary prompt; in non-interactive mode, the
308interpreter exits after printing the stack trace.
309The interrupt signal raises the
310.I Keyboard\%Interrupt
311exception; other UNIX signals are not caught (except that SIGPIPE is
312sometimes ignored, in favor of the
313.I IOError
314exception). Error messages are written to stderr.
315.SH FILES AND DIRECTORIES
316These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000317conventions; ${prefix} and ${exec_prefix} are installation-dependent
318and should be interpreted as for GNU software; they may be the same.
319The default for both is \fI/usr/local\fP.
320.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000321Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000322.PP
323.I ${prefix}/lib/python<version>
324.br
325.I ${exec_prefix}/lib/python<version>
326.RS
327Recommended locations of the directories containing the standard
328modules.
329.RE
330.PP
331.I ${prefix}/include/python<version>
332.br
333.I ${exec_prefix}/include/python<version>
334.RS
335Recommended locations of the directories containing the include files
336needed for developing Python extensions and embedding the
337interpreter.
338.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000339.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000340.IP PYTHONHOME
341Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000342libraries are searched in ${prefix}/lib/python<version> and
343${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000344are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000345\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
346replaces both ${prefix} and ${exec_prefix}. To specify different values
347for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000348.IP PYTHONPATH
349Augments the default search path for module files.
350The format is the same as the shell's $PATH: one or more directory
351pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000352Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000353The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000354begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000355The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000356If a script argument is given, the directory containing the script is
357inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000358The search path can be manipulated from within a Python program as the
359variable
360.I sys.path .
361.IP PYTHONSTARTUP
362If this is the name of a readable file, the Python commands in that
363file are executed before the first prompt is displayed in interactive
364mode.
365The file is executed in the same name space where interactive commands
366are executed so that objects defined or imported in it can be used
367without qualification in the interactive session.
368You can also change the prompts
369.I sys.ps1
370and
371.I sys.ps2
372in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000373.IP PYTHONY2K
374Set this to a non-empty string to cause the \fItime\fP module to
375require dates specified as strings to include 4-digit years, otherwise
3762-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000377module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000378.IP PYTHONOPTIMIZE
379If this is set to a non-empty string it is equivalent to specifying
380the \fB\-O\fP option. If set to an integer, it is equivalent to
381specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000382.IP PYTHONDEBUG
383If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000384the \fB\-d\fP option. If set to an integer, it is equivalent to
385specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000386.IP PYTHONDONTWRITEBYTECODE
387If this is set to a non-empty string it is equivalent to specifying
388the \fB\-B\fP option (don't try to write
389.I .py[co]
390files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000391.IP PYTHONINSPECT
392If this is set to a non-empty string it is equivalent to specifying
393the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000394.IP PYTHONIOENCODING
395If this is set before running the interpreter, it overrides the encoding used
396for stdin/stdout/stderr, in the syntax
397.IB encodingname ":" errorhandler
398The
399.IB errorhandler
400part is optional and has the same meaning as in str.encode. For stderr, the
401.IB errorhandler
402 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000403.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000404If this is set to a non-empty string it is equivalent to specifying the
405\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000406.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000407If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000408the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000409.IP PYTHONVERBOSE
410If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000411the \fB\-v\fP option. If set to an integer, it is equivalent to
412specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000413.IP PYTHONWARNINGS
414If this is set to a comma-separated string it is equivalent to
415specifying the \fB\-W\fP option for each separate value.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000416.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000417The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000418.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000419Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000420.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000421Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000422.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000423Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000424.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000425Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000426.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000427Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000428.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000429Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000430.SH LICENSING
431Python is distributed under an Open Source license. See the file
432"LICENSE" in the Python source distribution for information on terms &
433conditions for accessing and otherwise using Python and for a
434DISCLAIMER OF ALL WARRANTIES.