blob: 76b7c4f2be270266d5cee94cf9e859295bc7b4d2 [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
3./" To view this file while editing, run it through groff:
4./" groff -Tascii -man python.man | less
5
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 Rossum29d465b1998-04-10 19:36:09 +000038.B \-t
39]
40[
Guido van Rossumef5bca31994-05-03 14:15:32 +000041.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000042]
Guido van Rossumb674baf2001-09-05 18:55:34 +000043.br
44 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000045.B \-v
46]
Guido van Rossum07c44c71998-04-10 19:46:00 +000047[
Barry Warsaw64569372000-09-15 18:39:09 +000048.B \-V
49]
Guido van Rossum1378c322000-12-19 03:21:54 +000050[
51.B \-W
52.I argument
53]
Guido van Rossumb674baf2001-09-05 18:55:34 +000054[
55.B \-x
56]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000057.br
58 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000059.B \-c
60.I command
61|
62.I script
63|
64\-
65]
66[
67.I arguments
68]
69.SH DESCRIPTION
70Python is an interpreted, interactive, object-oriented programming
71language that combines remarkable power with very clear syntax.
72For an introduction to programming in Python you are referred to the
73Python Tutorial.
74The Python Library Reference documents built-in and standard types,
75constants, functions and modules.
76Finally, the Python Reference Manual describes the syntax and
77semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000078(These documents may be located via the
79.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000080below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000081.PP
82Python's basic power can be extended with your own modules written in
83C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000084On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000085Python is also adaptable as an extension language for existing
86applications.
87See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000088.PP
89Documentation for installed Python modules and packages can be
90viewed by running the
91.B pydoc
92program.
Guido van Rossuma7925f11994-01-26 10:20:16 +000093.SH COMMAND LINE OPTIONS
94.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000095.BI "\-c " command
96Specify the command to execute (see next section).
97This terminates the option list (following options are passed as
98arguments to the command).
99.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000100.B \-d
101Turn on parser debugging output (for wizards only, depending on
102compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000103.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000104.B \-E
105Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
106the behavior of the interpreter.
107.TP
108.B \-h
109Prints the usage for the interpreter executable and exits.
110.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000111.B \-i
112When a script is passed as first argument or the \fB\-c\fP option is
113used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000114command. It does not read the $PYTHONSTARTUP file. This can be
115useful to inspect global variables or a stack trace when a script
116raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000117.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000118.BI "\-m " module-name
119Searches
120.I sys.path
121for the named module and runs the corresponding
122.I .py
123file as a script.
124.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000125.B \-O
126Turn on basic optimizations. This changes the filename extension for
127compiled (bytecode) files from
128.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000129to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000130.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000131.BI "\-Q " argument
132Division control; see PEP 238. The argument must be one of "old" (the
133default, int/int and long/long return an int or long), "new" (new
134division semantics, i.e. int/int and long/long returns a float),
135"warn" (old division semantics with a warning for int/int and
136long/long), or "warnall" (old division semantics with a warning for
137all use of the division operator). For a use of "warnall", see the
138Tools/scripts/fixdiv.py script.
139.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000140.B \-S
141Disable the import of the module
142.I site
143and the site-dependent manipulations of
144.I sys.path
145that it entails.
146.TP
Guido van Rossum29d465b1998-04-10 19:36:09 +0000147.B \-t
148Issue a warning when a source file mixes tabs and spaces for
149indentation in a way that makes it depend on the worth of a tab
150expressed in spaces. Issue an error when the option is given twice.
151.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000152.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000153Force stdin, stdout and stderr to be totally unbuffered. On systems
154where it matters, also put stdin, stdout and stderr in binary mode.
155Note that there is internal buffering in xreadlines(), readlines() and
156file-object iterators ("for line in sys.stdin") which is not
157influenced by this option. To work around this, you will want to use
158"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000159.TP
160.B \-v
161Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000162(filename or built-in module) from which it is loaded. When given
163twice, print a message for each file that is checked for when
164searching for a module. Also provides information on module cleanup
165at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000166.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000167.B \-V
168Prints the Python version number of the executable and exits.
169.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000170.BI "\-W " argument
171Warning control. Python sometimes prints warning message to
172.IR sys.stderr .
173A typical warning message has the following form:
174.IB file ":" line ": " category ": " message.
175By default, each warning is printed once for each source line where it
176occurs. This option controls how often warnings are printed.
177Multiple
178.B \-W
179options may be given; when a warning matches more than one
180option, the action for the last matching option is performed.
181Invalid
182.B \-W
183options are ignored (a warning message is printed about invalid
184options when the first warning is issued). Warnings can also be
185controlled from within a Python program using the
186.I warnings
187module.
188
189The simplest form of
190.I argument
191is one of the following
192.I action
193strings (or a unique abbreviation):
194.B ignore
195to ignore all warnings;
196.B default
197to explicitly request the default behavior (printing each warning once
198per source line);
199.B all
200to print a warning each time it occurs (this may generate many
201messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000202line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000203.B module
204to print each warning only only the first time it occurs in each
205module;
206.B once
207to print each warning only the first time it occurs in the program; or
208.B error
209to raise an exception instead of printing a warning message.
210
211The full form of
212.I argument
213is
214.IB action : message : category : module : line.
215Here,
216.I action
217is as explained above but only applies to messages that match the
218remaining fields. Empty fields match all values; trailing empty
219fields may be omitted. The
220.I message
221field matches the start of the warning message printed; this match is
222case-insensitive. The
223.I category
224field matches the warning category. This must be a class name; the
225match test whether the actual warning category of the message is a
226subclass of the specified warning category. The full class name must
227be given. The
228.I module
229field matches the (fully-qualified) module name; this match is
230case-sensitive. The
231.I line
232field matches the line number, where zero matches all line numbers and
233is thus equivalent to an omitted line number.
234.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000235.B \-x
236Skip the first line of the source. This is intended for a DOS
237specific hack only. Warning: the line numbers in error messages will
238be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000239.SH INTERPRETER INTERFACE
240The interpreter interface resembles that of the UNIX shell: when
241called with standard input connected to a tty device, it prompts for
242commands and executes them until an EOF is read; when called with a
243file name argument or with a file as standard input, it reads and
244executes a
245.I script
246from that file;
247when called with
248.B \-c
249.I command,
250it executes the Python statement(s) given as
251.I command.
252Here
253.I command
254may contain multiple statements separated by newlines.
255Leading whitespace is significant in Python statements!
256In non-interactive mode, the entire input is parsed befored it is
257executed.
258.PP
259If available, the script name and additional arguments thereafter are
260passed to the script in the Python variable
261.I sys.argv ,
262which is a list of strings (you must first
263.I import sys
264to be able to access it).
265If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000266.I sys.argv[0]
267is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000268.B \-c
269is used,
270.I sys.argv[0]
271contains the string
272.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000273Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000274are not placed in
275.I sys.argv.
276.PP
277In interactive mode, the primary prompt is `>>>'; the second prompt
278(which appears when a command is not complete) is `...'.
279The prompts can be changed by assignment to
280.I sys.ps1
281or
282.I sys.ps2.
283The interpreter quits when it reads an EOF at a prompt.
284When an unhandled exception occurs, a stack trace is printed and
285control returns to the primary prompt; in non-interactive mode, the
286interpreter exits after printing the stack trace.
287The interrupt signal raises the
288.I Keyboard\%Interrupt
289exception; other UNIX signals are not caught (except that SIGPIPE is
290sometimes ignored, in favor of the
291.I IOError
292exception). Error messages are written to stderr.
293.SH FILES AND DIRECTORIES
294These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000295conventions; ${prefix} and ${exec_prefix} are installation-dependent
296and should be interpreted as for GNU software; they may be the same.
297The default for both is \fI/usr/local\fP.
298.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000299Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000300.PP
301.I ${prefix}/lib/python<version>
302.br
303.I ${exec_prefix}/lib/python<version>
304.RS
305Recommended locations of the directories containing the standard
306modules.
307.RE
308.PP
309.I ${prefix}/include/python<version>
310.br
311.I ${exec_prefix}/include/python<version>
312.RS
313Recommended locations of the directories containing the include files
314needed for developing Python extensions and embedding the
315interpreter.
316.RE
317.IP \fI~/.pythonrc.py\fP
318User-specific initialization file loaded by the \fIuser\fP module;
319not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000320.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000321.IP PYTHONHOME
322Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000323libraries are searched in ${prefix}/lib/python<version> and
324${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000325are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000326\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
327replaces both ${prefix} and ${exec_prefix}. To specify different values
328for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000329.IP PYTHONPATH
330Augments the default search path for module files.
331The format is the same as the shell's $PATH: one or more directory
332pathnames separated by colons.
333Non-existant directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000334The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000335begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000336The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000337If a script argument is given, the directory containing the script is
338inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000339The search path can be manipulated from within a Python program as the
340variable
341.I sys.path .
342.IP PYTHONSTARTUP
343If this is the name of a readable file, the Python commands in that
344file are executed before the first prompt is displayed in interactive
345mode.
346The file is executed in the same name space where interactive commands
347are executed so that objects defined or imported in it can be used
348without qualification in the interactive session.
349You can also change the prompts
350.I sys.ps1
351and
352.I sys.ps2
353in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000354.IP PYTHONY2K
355Set this to a non-empty string to cause the \fItime\fP module to
356require dates specified as strings to include 4-digit years, otherwise
3572-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000358module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000359.IP PYTHONOPTIMIZE
360If this is set to a non-empty string it is equivalent to specifying
361the \fB\-O\fP option. If set to an integer, it is equivalent to
362specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000363.IP PYTHONDEBUG
364If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000365the \fB\-d\fP option. If set to an integer, it is equivalent to
366specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000367.IP PYTHONINSPECT
368If this is set to a non-empty string it is equivalent to specifying
369the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000370.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000371If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000372the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000373.IP PYTHONVERBOSE
374If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000375the \fB\-v\fP option. If set to an integer, it is equivalent to
376specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000377.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000378The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000379.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000380Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000381.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000382Documentation: http://docs.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000383.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000384Community website: http://starship.python.net/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000385.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000386Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000387.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000388FTP: ftp://ftp.python.org/pub/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000389.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000390Module repository: http://www.vex.net/parnassus/
Guido van Rossum74faed21996-07-30 19:27:05 +0000391.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000392Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000393.SH LICENSING
394Python is distributed under an Open Source license. See the file
395"LICENSE" in the Python source distribution for information on terms &
396conditions for accessing and otherwise using Python and for a
397DISCLAIMER OF ALL WARRANTIES.