blob: 2aa1de88f1f375523de45add041bc604f0681250 [file] [log] [blame]
Guido van Rossum97bac532001-09-05 18:57:51 +00001.TH PYTHON "1" "$Date$"
Guido van Rossuma7925f11994-01-26 10:20:16 +00002.SH NAME
3python \- an interpreted, interactive, object-oriented programming language
4.SH SYNOPSIS
5.B python
6[
Guido van Rossuma7925f11994-01-26 10:20:16 +00007.B \-d
8]
9[
Guido van Rossumb674baf2001-09-05 18:55:34 +000010.B \-E
11]
12[
13.B \-h
14]
15[
Guido van Rossuma7925f11994-01-26 10:20:16 +000016.B \-i
17]
18[
Guido van Rossum4cf4de51997-09-08 04:06:15 +000019.B \-O
20]
Guido van Rossumb674baf2001-09-05 18:55:34 +000021.br
22 [
23.B -Q
24.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000025]
26[
Guido van Rossumb674baf2001-09-05 18:55:34 +000027.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000028]
29[
Guido van Rossum29d465b1998-04-10 19:36:09 +000030.B \-t
31]
32[
Guido van Rossumef5bca31994-05-03 14:15:32 +000033.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000034]
35[
Guido van Rossumb674baf2001-09-05 18:55:34 +000036.B \-U
37]
38.br
39 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000040.B \-v
41]
Guido van Rossum07c44c71998-04-10 19:46:00 +000042[
Barry Warsaw64569372000-09-15 18:39:09 +000043.B \-V
44]
Guido van Rossum1378c322000-12-19 03:21:54 +000045[
46.B \-W
47.I argument
48]
Guido van Rossumb674baf2001-09-05 18:55:34 +000049[
50.B \-x
51]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000052.br
53 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000054.B \-c
55.I command
56|
57.I script
58|
59\-
60]
61[
62.I arguments
63]
64.SH DESCRIPTION
65Python is an interpreted, interactive, object-oriented programming
66language that combines remarkable power with very clear syntax.
67For an introduction to programming in Python you are referred to the
68Python Tutorial.
69The Python Library Reference documents built-in and standard types,
70constants, functions and modules.
71Finally, the Python Reference Manual describes the syntax and
72semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000073(These documents may be located via the
74.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000075below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000076.PP
77Python's basic power can be extended with your own modules written in
78C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000079On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000080Python is also adaptable as an extension language for existing
81applications.
82See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000083.PP
84Documentation for installed Python modules and packages can be
85viewed by running the
86.B pydoc
87program.
Guido van Rossuma7925f11994-01-26 10:20:16 +000088.SH COMMAND LINE OPTIONS
89.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000090.BI "\-c " command
91Specify the command to execute (see next section).
92This terminates the option list (following options are passed as
93arguments to the command).
94.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +000095.B \-d
96Turn on parser debugging output (for wizards only, depending on
97compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +000098.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000099.B \-E
100Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
101the behavior of the interpreter.
102.TP
103.B \-h
104Prints the usage for the interpreter executable and exits.
105.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000106.B \-i
107When a script is passed as first argument or the \fB\-c\fP option is
108used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000109command. It does not read the $PYTHONSTARTUP file. This can be
110useful to inspect global variables or a stack trace when a script
111raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000112.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000113.B \-O
114Turn on basic optimizations. This changes the filename extension for
115compiled (bytecode) files from
116.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000117to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000118.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000119.BI "\-Q " argument
120Division control; see PEP 238. The argument must be one of "old" (the
121default, int/int and long/long return an int or long), "new" (new
122division semantics, i.e. int/int and long/long returns a float),
123"warn" (old division semantics with a warning for int/int and
124long/long), or "warnall" (old division semantics with a warning for
125all use of the division operator). For a use of "warnall", see the
126Tools/scripts/fixdiv.py script.
127.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000128.B \-S
129Disable the import of the module
130.I site
131and the site-dependent manipulations of
132.I sys.path
133that it entails.
134.TP
Guido van Rossum29d465b1998-04-10 19:36:09 +0000135.B \-t
136Issue a warning when a source file mixes tabs and spaces for
137indentation in a way that makes it depend on the worth of a tab
138expressed in spaces. Issue an error when the option is given twice.
139.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000140.B \-u
Martin v. Löwis611a7102002-07-28 10:34:08 +0000141Force stdin, stdout and stderr to be totally unbuffered. Note that
142there is internal buffering in xreadlines(), readlines() and file-object
143iterators ("for line in sys.stdin") which is not influenced by this
144option. To work around this, you will want to use "sys.stdin.readline()"
145inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000146.TP
147.B \-v
148Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000149(filename or built-in module) from which it is loaded. When given
150twice, print a message for each file that is checked for when
151searching for a module. Also provides information on module cleanup
152at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000153.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000154.B \-V
155Prints the Python version number of the executable and exits.
156.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000157.BI "\-W " argument
158Warning control. Python sometimes prints warning message to
159.IR sys.stderr .
160A typical warning message has the following form:
161.IB file ":" line ": " category ": " message.
162By default, each warning is printed once for each source line where it
163occurs. This option controls how often warnings are printed.
164Multiple
165.B \-W
166options may be given; when a warning matches more than one
167option, the action for the last matching option is performed.
168Invalid
169.B \-W
170options are ignored (a warning message is printed about invalid
171options when the first warning is issued). Warnings can also be
172controlled from within a Python program using the
173.I warnings
174module.
175
176The simplest form of
177.I argument
178is one of the following
179.I action
180strings (or a unique abbreviation):
181.B ignore
182to ignore all warnings;
183.B default
184to explicitly request the default behavior (printing each warning once
185per source line);
186.B all
187to print a warning each time it occurs (this may generate many
188messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000189line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000190.B module
191to print each warning only only the first time it occurs in each
192module;
193.B once
194to print each warning only the first time it occurs in the program; or
195.B error
196to raise an exception instead of printing a warning message.
197
198The full form of
199.I argument
200is
201.IB action : message : category : module : line.
202Here,
203.I action
204is as explained above but only applies to messages that match the
205remaining fields. Empty fields match all values; trailing empty
206fields may be omitted. The
207.I message
208field matches the start of the warning message printed; this match is
209case-insensitive. The
210.I category
211field matches the warning category. This must be a class name; the
212match test whether the actual warning category of the message is a
213subclass of the specified warning category. The full class name must
214be given. The
215.I module
216field matches the (fully-qualified) module name; this match is
217case-sensitive. The
218.I line
219field matches the line number, where zero matches all line numbers and
220is thus equivalent to an omitted line number.
221.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000222.B \-x
223Skip the first line of the source. This is intended for a DOS
224specific hack only. Warning: the line numbers in error messages will
225be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000226.SH INTERPRETER INTERFACE
227The interpreter interface resembles that of the UNIX shell: when
228called with standard input connected to a tty device, it prompts for
229commands and executes them until an EOF is read; when called with a
230file name argument or with a file as standard input, it reads and
231executes a
232.I script
233from that file;
234when called with
235.B \-c
236.I command,
237it executes the Python statement(s) given as
238.I command.
239Here
240.I command
241may contain multiple statements separated by newlines.
242Leading whitespace is significant in Python statements!
243In non-interactive mode, the entire input is parsed befored it is
244executed.
245.PP
246If available, the script name and additional arguments thereafter are
247passed to the script in the Python variable
248.I sys.argv ,
249which is a list of strings (you must first
250.I import sys
251to be able to access it).
252If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000253.I sys.argv[0]
254is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000255.B \-c
256is used,
257.I sys.argv[0]
258contains the string
259.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000260Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000261are not placed in
262.I sys.argv.
263.PP
264In interactive mode, the primary prompt is `>>>'; the second prompt
265(which appears when a command is not complete) is `...'.
266The prompts can be changed by assignment to
267.I sys.ps1
268or
269.I sys.ps2.
270The interpreter quits when it reads an EOF at a prompt.
271When an unhandled exception occurs, a stack trace is printed and
272control returns to the primary prompt; in non-interactive mode, the
273interpreter exits after printing the stack trace.
274The interrupt signal raises the
275.I Keyboard\%Interrupt
276exception; other UNIX signals are not caught (except that SIGPIPE is
277sometimes ignored, in favor of the
278.I IOError
279exception). Error messages are written to stderr.
280.SH FILES AND DIRECTORIES
281These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000282conventions; ${prefix} and ${exec_prefix} are installation-dependent
283and should be interpreted as for GNU software; they may be the same.
284The default for both is \fI/usr/local\fP.
285.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000286Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000287.PP
288.I ${prefix}/lib/python<version>
289.br
290.I ${exec_prefix}/lib/python<version>
291.RS
292Recommended locations of the directories containing the standard
293modules.
294.RE
295.PP
296.I ${prefix}/include/python<version>
297.br
298.I ${exec_prefix}/include/python<version>
299.RS
300Recommended locations of the directories containing the include files
301needed for developing Python extensions and embedding the
302interpreter.
303.RE
304.IP \fI~/.pythonrc.py\fP
305User-specific initialization file loaded by the \fIuser\fP module;
306not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000307.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000308.IP PYTHONHOME
309Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000310libraries are searched in ${prefix}/lib/python<version> and
311${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000312are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000313\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
314replaces both ${prefix} and ${exec_prefix}. To specify different values
315for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000316.IP PYTHONPATH
317Augments the default search path for module files.
318The format is the same as the shell's $PATH: one or more directory
319pathnames separated by colons.
320Non-existant directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000321The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000322begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000323The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000324If a script argument is given, the directory containing the script is
325inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000326The search path can be manipulated from within a Python program as the
327variable
328.I sys.path .
329.IP PYTHONSTARTUP
330If this is the name of a readable file, the Python commands in that
331file are executed before the first prompt is displayed in interactive
332mode.
333The file is executed in the same name space where interactive commands
334are executed so that objects defined or imported in it can be used
335without qualification in the interactive session.
336You can also change the prompts
337.I sys.ps1
338and
339.I sys.ps2
340in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000341.IP PYTHONY2K
342Set this to a non-empty string to cause the \fItime\fP module to
343require dates specified as strings to include 4-digit years, otherwise
3442-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000345module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000346.IP PYTHONOPTIMIZE
347If this is set to a non-empty string it is equivalent to specifying
348the \fB\-O\fP option. If set to an integer, it is equivalent to
349specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000350.IP PYTHONDEBUG
351If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000352the \fB\-d\fP option. If set to an integer, it is equivalent to
353specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000354.IP PYTHONINSPECT
355If this is set to a non-empty string it is equivalent to specifying
356the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000357.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000358If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000359the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000360.IP PYTHONVERBOSE
361If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000362the \fB\-v\fP option. If set to an integer, it is equivalent to
363specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000364.SH AUTHOR
365.nf
366Guido van Rossum
Guido van Rossuma7925f11994-01-26 10:20:16 +0000367.PP
Guido van Rossum1378c322000-12-19 03:21:54 +0000368E-mail: guido@python.org
Guido van Rossuma7925f11994-01-26 10:20:16 +0000369.fi
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000370.PP
371And a cast of thousands.
Guido van Rossum74faed21996-07-30 19:27:05 +0000372.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000373Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000374.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000375Documentation: http://www.python.org/doc/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000376.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000377Community website: http://starship.python.net/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000378.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000379Developer resources: http://sourceforge.net/project/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000380.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000381FTP: ftp://ftp.python.org/pub/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000382.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000383Module repository: http://www.vex.net/parnassus/
Guido van Rossum74faed21996-07-30 19:27:05 +0000384.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000385Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000386.SH LICENSING
387Python is distributed under an Open Source license. See the file
388"LICENSE" in the Python source distribution for information on terms &
389conditions for accessing and otherwise using Python and for a
390DISCLAIMER OF ALL WARRANTIES.