blob: 261a118944ffbe2193338ca94ee2461c6a205526 [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
Matthias Klose8ed25202009-03-22 13:08:22 +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 Klose626d92a2010-01-31 16:05:13 +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]
Guido van Rossumb674baf2001-09-05 18:55:34 +000029.br
30 [
Matthias Klose626d92a2010-01-31 16:05:13 +000031.B \-O
32]
33[
34.B \-O0
35]
36[
Guido van Rossumb674baf2001-09-05 18:55:34 +000037.B -Q
38.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000039]
40[
Matthias Klose626d92a2010-01-31 16:05:13 +000041.B \-s
42]
43[
Guido van Rossumb674baf2001-09-05 18:55:34 +000044.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000045]
46[
Guido van Rossum29d465b1998-04-10 19:36:09 +000047.B \-t
48]
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]
Benjamin Petersonc4431ee2009-01-09 03:05:14 +000066[
67.B \-3
68]
Matthias Klose626d92a2010-01-31 16:05:13 +000069[
70.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 Klose626d92a2010-01-31 16:05:13 +0000110.B \-B
111Don't write
112.I .py[co]
113files on import. See also PYTHONDONTWRITEBYTECODE.
114.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000115.BI "\-c " command
116Specify the command to execute (see next section).
117This terminates the option list (following options are passed as
118arguments to the command).
119.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000120.B \-d
121Turn on parser debugging output (for wizards only, depending on
122compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000123.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000124.B \-E
125Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
126the behavior of the interpreter.
127.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000128.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000129Prints the usage for the interpreter executable and exits.
130.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000131.B \-i
132When a script is passed as first argument or the \fB\-c\fP option is
133used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000134command. It does not read the $PYTHONSTARTUP file. This can be
135useful to inspect global variables or a stack trace when a script
136raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000137.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000138.BI "\-m " module-name
139Searches
140.I sys.path
141for the named module and runs the corresponding
142.I .py
143file as a script.
144.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000145.B \-O
146Turn on basic optimizations. This changes the filename extension for
147compiled (bytecode) files from
148.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000149to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000150.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000151.B \-O0
152Discard docstrings in addition to the \fB-O\fP optimizations.
153.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000154.BI "\-Q " argument
155Division control; see PEP 238. The argument must be one of "old" (the
156default, int/int and long/long return an int or long), "new" (new
157division semantics, i.e. int/int and long/long returns a float),
158"warn" (old division semantics with a warning for int/int and
159long/long), or "warnall" (old division semantics with a warning for
160all use of the division operator). For a use of "warnall", see the
161Tools/scripts/fixdiv.py script.
162.TP
Matthias Klose626d92a2010-01-31 16:05:13 +0000163.B \-s
164Don't add user site directory to sys.path.
165.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000166.B \-S
167Disable the import of the module
168.I site
169and the site-dependent manipulations of
170.I sys.path
171that it entails.
172.TP
Guido van Rossum29d465b1998-04-10 19:36:09 +0000173.B \-t
174Issue a warning when a source file mixes tabs and spaces for
175indentation in a way that makes it depend on the worth of a tab
176expressed in spaces. Issue an error when the option is given twice.
177.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000178.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000179Force stdin, stdout and stderr to be totally unbuffered. On systems
180where it matters, also put stdin, stdout and stderr in binary mode.
181Note that there is internal buffering in xreadlines(), readlines() and
182file-object iterators ("for line in sys.stdin") which is not
183influenced 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 Klose626d92a2010-01-31 16:05:13 +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 Brandl5a85d5c2009-06-24 06:41:19 +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!
Benjamin Petersonc4431ee2009-01-09 03:05:14 +0000265.TP
266.B \-3
267Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000268.SH INTERPRETER INTERFACE
269The interpreter interface resembles that of the UNIX shell: when
270called with standard input connected to a tty device, it prompts for
271commands and executes them until an EOF is read; when called with a
272file name argument or with a file as standard input, it reads and
273executes a
274.I script
275from that file;
276when called with
277.B \-c
278.I command,
279it executes the Python statement(s) given as
280.I command.
281Here
282.I command
283may contain multiple statements separated by newlines.
284Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000285In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000286executed.
287.PP
288If available, the script name and additional arguments thereafter are
289passed to the script in the Python variable
290.I sys.argv ,
291which is a list of strings (you must first
292.I import sys
293to be able to access it).
294If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000295.I sys.argv[0]
296is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000297.B \-c
298is used,
299.I sys.argv[0]
300contains the string
301.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000302Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000303are not placed in
304.I sys.argv.
305.PP
306In interactive mode, the primary prompt is `>>>'; the second prompt
307(which appears when a command is not complete) is `...'.
308The prompts can be changed by assignment to
309.I sys.ps1
310or
311.I sys.ps2.
312The interpreter quits when it reads an EOF at a prompt.
313When an unhandled exception occurs, a stack trace is printed and
314control returns to the primary prompt; in non-interactive mode, the
315interpreter exits after printing the stack trace.
316The interrupt signal raises the
317.I Keyboard\%Interrupt
318exception; other UNIX signals are not caught (except that SIGPIPE is
319sometimes ignored, in favor of the
320.I IOError
321exception). Error messages are written to stderr.
322.SH FILES AND DIRECTORIES
323These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000324conventions; ${prefix} and ${exec_prefix} are installation-dependent
325and should be interpreted as for GNU software; they may be the same.
326The default for both is \fI/usr/local\fP.
327.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000328Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000329.PP
330.I ${prefix}/lib/python<version>
331.br
332.I ${exec_prefix}/lib/python<version>
333.RS
334Recommended locations of the directories containing the standard
335modules.
336.RE
337.PP
338.I ${prefix}/include/python<version>
339.br
340.I ${exec_prefix}/include/python<version>
341.RS
342Recommended locations of the directories containing the include files
343needed for developing Python extensions and embedding the
344interpreter.
345.RE
346.IP \fI~/.pythonrc.py\fP
347User-specific initialization file loaded by the \fIuser\fP module;
348not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000349.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000350.IP PYTHONHOME
351Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000352libraries are searched in ${prefix}/lib/python<version> and
353${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000354are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000355\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
356replaces both ${prefix} and ${exec_prefix}. To specify different values
357for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000358.IP PYTHONPATH
359Augments the default search path for module files.
360The format is the same as the shell's $PATH: one or more directory
361pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000362Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000363The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000364begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000365The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000366If a script argument is given, the directory containing the script is
367inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000368The search path can be manipulated from within a Python program as the
369variable
370.I sys.path .
371.IP PYTHONSTARTUP
372If this is the name of a readable file, the Python commands in that
373file are executed before the first prompt is displayed in interactive
374mode.
375The file is executed in the same name space where interactive commands
376are executed so that objects defined or imported in it can be used
377without qualification in the interactive session.
378You can also change the prompts
379.I sys.ps1
380and
381.I sys.ps2
382in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000383.IP PYTHONY2K
384Set this to a non-empty string to cause the \fItime\fP module to
385require dates specified as strings to include 4-digit years, otherwise
3862-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000387module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000388.IP PYTHONOPTIMIZE
389If this is set to a non-empty string it is equivalent to specifying
390the \fB\-O\fP option. If set to an integer, it is equivalent to
391specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000392.IP PYTHONDEBUG
393If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000394the \fB\-d\fP option. If set to an integer, it is equivalent to
395specifying \fB\-d\fP multiple times.
Matthias Klose626d92a2010-01-31 16:05:13 +0000396.IP PYTHONDONTWRITEBYTECODE
397If this is set to a non-empty string it is equivalent to specifying
398the \fB\-B\fP option (don't try to write
399.I .py[co]
400files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000401.IP PYTHONINSPECT
402If this is set to a non-empty string it is equivalent to specifying
403the \fB\-i\fP option.
Matthias Klose626d92a2010-01-31 16:05:13 +0000404.IP PYTHONNOUSERSITE
405If this is set to a non-empty string it is equivalent to specifying
406the \fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000407.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000408If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000409the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000410.IP PYTHONVERBOSE
411If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000412the \fB\-v\fP option. If set to an integer, it is equivalent to
413specifying \fB\-v\fP multiple times.
Philip Jenvey5a5a37c2010-04-06 23:38:57 +0000414.IP PYTHONWARNINGS
415If this is set to a comma-separated string it is equivalent to
416specifying the \fB\-W\fP option for each separate value.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000417.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000418The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000419.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000420Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000421.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000422Documentation: http://docs.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000423.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000424Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000425.br
Benjamin Peterson3d854542009-09-13 01:59:31 +0000426Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000427.br
Benjamin Peterson3d854542009-09-13 01:59:31 +0000428Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000429.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000430Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000431.SH LICENSING
432Python is distributed under an Open Source license. See the file
433"LICENSE" in the Python source distribution for information on terms &
434conditions for accessing and otherwise using Python and for a
435DISCLAIMER OF ALL WARRANTIES.