blob: 2f0e744485450688245be977e84ecfdadf0f67aa [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[
Guido van Rossuma7925f11994-01-26 10:20:16 +000011.B \-d
12]
13[
Guido van Rossumb674baf2001-09-05 18:55:34 +000014.B \-E
15]
16[
17.B \-h
18]
19[
Guido van Rossuma7925f11994-01-26 10:20:16 +000020.B \-i
21]
22[
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000023.B \-m
24.I module-name
25]
26[
Guido van Rossum4cf4de51997-09-08 04:06:15 +000027.B \-O
28]
Guido van Rossumb674baf2001-09-05 18:55:34 +000029.br
30 [
31.B -Q
32.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000033]
34[
Guido van Rossumb674baf2001-09-05 18:55:34 +000035.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000036]
37[
Guido van Rossumef5bca31994-05-03 14:15:32 +000038.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000039]
Guido van Rossumb674baf2001-09-05 18:55:34 +000040.br
41 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000042.B \-v
43]
Guido van Rossum07c44c71998-04-10 19:46:00 +000044[
Barry Warsaw64569372000-09-15 18:39:09 +000045.B \-V
46]
Guido van Rossum1378c322000-12-19 03:21:54 +000047[
48.B \-W
49.I argument
50]
Guido van Rossumb674baf2001-09-05 18:55:34 +000051[
52.B \-x
53]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000054.br
55 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000056.B \-c
57.I command
58|
59.I script
60|
61\-
62]
63[
64.I arguments
65]
66.SH DESCRIPTION
67Python is an interpreted, interactive, object-oriented programming
68language that combines remarkable power with very clear syntax.
69For an introduction to programming in Python you are referred to the
70Python Tutorial.
71The Python Library Reference documents built-in and standard types,
72constants, functions and modules.
73Finally, the Python Reference Manual describes the syntax and
74semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000075(These documents may be located via the
76.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000077below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000078.PP
79Python's basic power can be extended with your own modules written in
80C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000081On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000082Python is also adaptable as an extension language for existing
83applications.
84See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000085.PP
86Documentation for installed Python modules and packages can be
87viewed by running the
88.B pydoc
89program.
Guido van Rossuma7925f11994-01-26 10:20:16 +000090.SH COMMAND LINE OPTIONS
91.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000092.BI "\-c " command
93Specify the command to execute (see next section).
94This terminates the option list (following options are passed as
95arguments to the command).
96.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +000097.B \-d
98Turn on parser debugging output (for wizards only, depending on
99compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000100.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000101.B \-E
102Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
103the behavior of the interpreter.
104.TP
105.B \-h
106Prints the usage for the interpreter executable and exits.
107.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000108.B \-i
109When a script is passed as first argument or the \fB\-c\fP option is
110used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000111command. It does not read the $PYTHONSTARTUP file. This can be
112useful to inspect global variables or a stack trace when a script
113raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000114.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000115.BI "\-m " module-name
116Searches
117.I sys.path
118for the named module and runs the corresponding
119.I .py
120file as a script.
121.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000122.B \-O
123Turn on basic optimizations. This changes the filename extension for
124compiled (bytecode) files from
125.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000126to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000127.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000128.BI "\-Q " argument
129Division control; see PEP 238. The argument must be one of "old" (the
130default, int/int and long/long return an int or long), "new" (new
131division semantics, i.e. int/int and long/long returns a float),
132"warn" (old division semantics with a warning for int/int and
133long/long), or "warnall" (old division semantics with a warning for
134all use of the division operator). For a use of "warnall", see the
135Tools/scripts/fixdiv.py script.
136.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000137.B \-S
138Disable the import of the module
139.I site
140and the site-dependent manipulations of
141.I sys.path
142that it entails.
143.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000144.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000145Force stdin, stdout and stderr to be totally unbuffered. On systems
146where it matters, also put stdin, stdout and stderr in binary mode.
Neal Norwitz70967602006-03-17 08:29:44 +0000147Note that there is internal buffering in readlines() and
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000148file-object iterators ("for line in sys.stdin") which is not
149influenced by this option. To work around this, you will want to use
150"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000151.TP
152.B \-v
153Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000154(filename or built-in module) from which it is loaded. When given
155twice, print a message for each file that is checked for when
156searching for a module. Also provides information on module cleanup
157at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000158.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000159.B \-V
160Prints the Python version number of the executable and exits.
161.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000162.BI "\-W " argument
163Warning control. Python sometimes prints warning message to
164.IR sys.stderr .
165A typical warning message has the following form:
166.IB file ":" line ": " category ": " message.
167By default, each warning is printed once for each source line where it
168occurs. This option controls how often warnings are printed.
169Multiple
170.B \-W
171options may be given; when a warning matches more than one
172option, the action for the last matching option is performed.
173Invalid
174.B \-W
175options are ignored (a warning message is printed about invalid
176options when the first warning is issued). Warnings can also be
177controlled from within a Python program using the
178.I warnings
179module.
180
181The simplest form of
182.I argument
183is one of the following
184.I action
185strings (or a unique abbreviation):
186.B ignore
187to ignore all warnings;
188.B default
189to explicitly request the default behavior (printing each warning once
190per source line);
191.B all
192to print a warning each time it occurs (this may generate many
193messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000194line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000195.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000196to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000197module;
198.B once
199to print each warning only the first time it occurs in the program; or
200.B error
201to raise an exception instead of printing a warning message.
202
203The full form of
204.I argument
205is
206.IB action : message : category : module : line.
207Here,
208.I action
209is as explained above but only applies to messages that match the
210remaining fields. Empty fields match all values; trailing empty
211fields may be omitted. The
212.I message
213field matches the start of the warning message printed; this match is
214case-insensitive. The
215.I category
216field matches the warning category. This must be a class name; the
217match test whether the actual warning category of the message is a
218subclass of the specified warning category. The full class name must
219be given. The
220.I module
221field matches the (fully-qualified) module name; this match is
222case-sensitive. The
223.I line
224field matches the line number, where zero matches all line numbers and
225is thus equivalent to an omitted line number.
226.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000227.B \-x
228Skip the first line of the source. This is intended for a DOS
229specific hack only. Warning: the line numbers in error messages will
230be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000231.SH INTERPRETER INTERFACE
232The interpreter interface resembles that of the UNIX shell: when
233called with standard input connected to a tty device, it prompts for
234commands and executes them until an EOF is read; when called with a
235file name argument or with a file as standard input, it reads and
236executes a
237.I script
238from that file;
239when called with
240.B \-c
241.I command,
242it executes the Python statement(s) given as
243.I command.
244Here
245.I command
246may contain multiple statements separated by newlines.
247Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000248In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000249executed.
250.PP
251If available, the script name and additional arguments thereafter are
252passed to the script in the Python variable
253.I sys.argv ,
254which is a list of strings (you must first
255.I import sys
256to be able to access it).
257If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000258.I sys.argv[0]
259is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000260.B \-c
261is used,
262.I sys.argv[0]
263contains the string
264.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000265Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000266are not placed in
267.I sys.argv.
268.PP
269In interactive mode, the primary prompt is `>>>'; the second prompt
270(which appears when a command is not complete) is `...'.
271The prompts can be changed by assignment to
272.I sys.ps1
273or
274.I sys.ps2.
275The interpreter quits when it reads an EOF at a prompt.
276When an unhandled exception occurs, a stack trace is printed and
277control returns to the primary prompt; in non-interactive mode, the
278interpreter exits after printing the stack trace.
279The interrupt signal raises the
280.I Keyboard\%Interrupt
281exception; other UNIX signals are not caught (except that SIGPIPE is
282sometimes ignored, in favor of the
283.I IOError
284exception). Error messages are written to stderr.
285.SH FILES AND DIRECTORIES
286These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000287conventions; ${prefix} and ${exec_prefix} are installation-dependent
288and should be interpreted as for GNU software; they may be the same.
289The default for both is \fI/usr/local\fP.
290.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000291Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000292.PP
293.I ${prefix}/lib/python<version>
294.br
295.I ${exec_prefix}/lib/python<version>
296.RS
297Recommended locations of the directories containing the standard
298modules.
299.RE
300.PP
301.I ${prefix}/include/python<version>
302.br
303.I ${exec_prefix}/include/python<version>
304.RS
305Recommended locations of the directories containing the include files
306needed for developing Python extensions and embedding the
307interpreter.
308.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000309.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000310.IP PYTHONHOME
311Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000312libraries are searched in ${prefix}/lib/python<version> and
313${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000314are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000315\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
316replaces both ${prefix} and ${exec_prefix}. To specify different values
317for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000318.IP PYTHONPATH
319Augments the default search path for module files.
320The format is the same as the shell's $PATH: one or more directory
321pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000322Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000323The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000324begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000325The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000326If a script argument is given, the directory containing the script is
327inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000328The search path can be manipulated from within a Python program as the
329variable
330.I sys.path .
331.IP PYTHONSTARTUP
332If this is the name of a readable file, the Python commands in that
333file are executed before the first prompt is displayed in interactive
334mode.
335The file is executed in the same name space where interactive commands
336are executed so that objects defined or imported in it can be used
337without qualification in the interactive session.
338You can also change the prompts
339.I sys.ps1
340and
341.I sys.ps2
342in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000343.IP PYTHONY2K
344Set this to a non-empty string to cause the \fItime\fP module to
345require dates specified as strings to include 4-digit years, otherwise
3462-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000347module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000348.IP PYTHONOPTIMIZE
349If this is set to a non-empty string it is equivalent to specifying
350the \fB\-O\fP option. If set to an integer, it is equivalent to
351specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000352.IP PYTHONDEBUG
353If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000354the \fB\-d\fP option. If set to an integer, it is equivalent to
355specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356.IP PYTHONINSPECT
357If this is set to a non-empty string it is equivalent to specifying
358the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000359.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000360If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000361the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000362.IP PYTHONVERBOSE
363If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000364the \fB\-v\fP option. If set to an integer, it is equivalent to
365specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000366.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000367The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000368.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000369Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000370.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000371Documentation: http://docs.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000372.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000373Community website: http://starship.python.net/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000374.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000375Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000376.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000377FTP: ftp://ftp.python.org/pub/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000378.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000379Module repository: http://www.vex.net/parnassus/
Guido van Rossum74faed21996-07-30 19:27:05 +0000380.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000381Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000382.SH LICENSING
383Python is distributed under an Open Source license. See the file
384"LICENSE" in the Python source distribution for information on terms &
385conditions for accessing and otherwise using Python and for a
386DISCLAIMER OF ALL WARRANTIES.