blob: 1e85a6b42e47968bf024408b9276b7121c119c0d [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]
Guido van Rossumb674baf2001-09-05 18:55:34 +000035.br
36 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000037.B \-v
38]
Guido van Rossum07c44c71998-04-10 19:46:00 +000039[
Barry Warsaw64569372000-09-15 18:39:09 +000040.B \-V
41]
Guido van Rossum1378c322000-12-19 03:21:54 +000042[
43.B \-W
44.I argument
45]
Guido van Rossumb674baf2001-09-05 18:55:34 +000046[
47.B \-x
48]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000049.br
50 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000051.B \-c
52.I command
53|
54.I script
55|
56\-
57]
58[
59.I arguments
60]
61.SH DESCRIPTION
62Python is an interpreted, interactive, object-oriented programming
63language that combines remarkable power with very clear syntax.
64For an introduction to programming in Python you are referred to the
65Python Tutorial.
66The Python Library Reference documents built-in and standard types,
67constants, functions and modules.
68Finally, the Python Reference Manual describes the syntax and
69semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000070(These documents may be located via the
71.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000072below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000073.PP
74Python's basic power can be extended with your own modules written in
75C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000076On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000077Python is also adaptable as an extension language for existing
78applications.
79See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000080.PP
81Documentation for installed Python modules and packages can be
82viewed by running the
83.B pydoc
84program.
Guido van Rossuma7925f11994-01-26 10:20:16 +000085.SH COMMAND LINE OPTIONS
86.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000087.BI "\-c " command
88Specify the command to execute (see next section).
89This terminates the option list (following options are passed as
90arguments to the command).
91.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +000092.B \-d
93Turn on parser debugging output (for wizards only, depending on
94compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +000095.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +000096.B \-E
97Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
98the behavior of the interpreter.
99.TP
100.B \-h
101Prints the usage for the interpreter executable and exits.
102.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000103.B \-i
104When a script is passed as first argument or the \fB\-c\fP option is
105used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000106command. It does not read the $PYTHONSTARTUP file. This can be
107useful to inspect global variables or a stack trace when a script
108raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000109.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000110.B \-O
111Turn on basic optimizations. This changes the filename extension for
112compiled (bytecode) files from
113.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000114to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000115.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000116.BI "\-Q " argument
117Division control; see PEP 238. The argument must be one of "old" (the
118default, int/int and long/long return an int or long), "new" (new
119division semantics, i.e. int/int and long/long returns a float),
120"warn" (old division semantics with a warning for int/int and
121long/long), or "warnall" (old division semantics with a warning for
122all use of the division operator). For a use of "warnall", see the
123Tools/scripts/fixdiv.py script.
124.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000125.B \-S
126Disable the import of the module
127.I site
128and the site-dependent manipulations of
129.I sys.path
130that it entails.
131.TP
Guido van Rossum29d465b1998-04-10 19:36:09 +0000132.B \-t
133Issue a warning when a source file mixes tabs and spaces for
134indentation in a way that makes it depend on the worth of a tab
135expressed in spaces. Issue an error when the option is given twice.
136.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000137.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000138Force stdin, stdout and stderr to be totally unbuffered. On systems
139where it matters, also put stdin, stdout and stderr in binary mode.
140Note that there is internal buffering in xreadlines(), readlines() and
141file-object iterators ("for line in sys.stdin") which is not
142influenced by this option. To work around this, you will want to use
143"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000144.TP
145.B \-v
146Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000147(filename or built-in module) from which it is loaded. When given
148twice, print a message for each file that is checked for when
149searching for a module. Also provides information on module cleanup
150at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000151.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000152.B \-V
153Prints the Python version number of the executable and exits.
154.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000155.BI "\-W " argument
156Warning control. Python sometimes prints warning message to
157.IR sys.stderr .
158A typical warning message has the following form:
159.IB file ":" line ": " category ": " message.
160By default, each warning is printed once for each source line where it
161occurs. This option controls how often warnings are printed.
162Multiple
163.B \-W
164options may be given; when a warning matches more than one
165option, the action for the last matching option is performed.
166Invalid
167.B \-W
168options are ignored (a warning message is printed about invalid
169options when the first warning is issued). Warnings can also be
170controlled from within a Python program using the
171.I warnings
172module.
173
174The simplest form of
175.I argument
176is one of the following
177.I action
178strings (or a unique abbreviation):
179.B ignore
180to ignore all warnings;
181.B default
182to explicitly request the default behavior (printing each warning once
183per source line);
184.B all
185to print a warning each time it occurs (this may generate many
186messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000187line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000188.B module
189to print each warning only only the first time it occurs in each
190module;
191.B once
192to print each warning only the first time it occurs in the program; or
193.B error
194to raise an exception instead of printing a warning message.
195
196The full form of
197.I argument
198is
199.IB action : message : category : module : line.
200Here,
201.I action
202is as explained above but only applies to messages that match the
203remaining fields. Empty fields match all values; trailing empty
204fields may be omitted. The
205.I message
206field matches the start of the warning message printed; this match is
207case-insensitive. The
208.I category
209field matches the warning category. This must be a class name; the
210match test whether the actual warning category of the message is a
211subclass of the specified warning category. The full class name must
212be given. The
213.I module
214field matches the (fully-qualified) module name; this match is
215case-sensitive. The
216.I line
217field matches the line number, where zero matches all line numbers and
218is thus equivalent to an omitted line number.
219.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000220.B \-x
221Skip the first line of the source. This is intended for a DOS
222specific hack only. Warning: the line numbers in error messages will
223be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000224.SH INTERPRETER INTERFACE
225The interpreter interface resembles that of the UNIX shell: when
226called with standard input connected to a tty device, it prompts for
227commands and executes them until an EOF is read; when called with a
228file name argument or with a file as standard input, it reads and
229executes a
230.I script
231from that file;
232when called with
233.B \-c
234.I command,
235it executes the Python statement(s) given as
236.I command.
237Here
238.I command
239may contain multiple statements separated by newlines.
240Leading whitespace is significant in Python statements!
241In non-interactive mode, the entire input is parsed befored it is
242executed.
243.PP
244If available, the script name and additional arguments thereafter are
245passed to the script in the Python variable
246.I sys.argv ,
247which is a list of strings (you must first
248.I import sys
249to be able to access it).
250If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000251.I sys.argv[0]
252is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000253.B \-c
254is used,
255.I sys.argv[0]
256contains the string
257.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000258Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000259are not placed in
260.I sys.argv.
261.PP
262In interactive mode, the primary prompt is `>>>'; the second prompt
263(which appears when a command is not complete) is `...'.
264The prompts can be changed by assignment to
265.I sys.ps1
266or
267.I sys.ps2.
268The interpreter quits when it reads an EOF at a prompt.
269When an unhandled exception occurs, a stack trace is printed and
270control returns to the primary prompt; in non-interactive mode, the
271interpreter exits after printing the stack trace.
272The interrupt signal raises the
273.I Keyboard\%Interrupt
274exception; other UNIX signals are not caught (except that SIGPIPE is
275sometimes ignored, in favor of the
276.I IOError
277exception). Error messages are written to stderr.
278.SH FILES AND DIRECTORIES
279These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000280conventions; ${prefix} and ${exec_prefix} are installation-dependent
281and should be interpreted as for GNU software; they may be the same.
282The default for both is \fI/usr/local\fP.
283.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000284Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000285.PP
286.I ${prefix}/lib/python<version>
287.br
288.I ${exec_prefix}/lib/python<version>
289.RS
290Recommended locations of the directories containing the standard
291modules.
292.RE
293.PP
294.I ${prefix}/include/python<version>
295.br
296.I ${exec_prefix}/include/python<version>
297.RS
298Recommended locations of the directories containing the include files
299needed for developing Python extensions and embedding the
300interpreter.
301.RE
302.IP \fI~/.pythonrc.py\fP
303User-specific initialization file loaded by the \fIuser\fP module;
304not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000305.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000306.IP PYTHONHOME
307Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000308libraries are searched in ${prefix}/lib/python<version> and
309${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000310are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000311\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
312replaces both ${prefix} and ${exec_prefix}. To specify different values
313for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000314.IP PYTHONPATH
315Augments the default search path for module files.
316The format is the same as the shell's $PATH: one or more directory
317pathnames separated by colons.
318Non-existant directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000319The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000320begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000321The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000322If a script argument is given, the directory containing the script is
323inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000324The search path can be manipulated from within a Python program as the
325variable
326.I sys.path .
327.IP PYTHONSTARTUP
328If this is the name of a readable file, the Python commands in that
329file are executed before the first prompt is displayed in interactive
330mode.
331The file is executed in the same name space where interactive commands
332are executed so that objects defined or imported in it can be used
333without qualification in the interactive session.
334You can also change the prompts
335.I sys.ps1
336and
337.I sys.ps2
338in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000339.IP PYTHONY2K
340Set this to a non-empty string to cause the \fItime\fP module to
341require dates specified as strings to include 4-digit years, otherwise
3422-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000343module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000344.IP PYTHONOPTIMIZE
345If this is set to a non-empty string it is equivalent to specifying
346the \fB\-O\fP option. If set to an integer, it is equivalent to
347specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000348.IP PYTHONDEBUG
349If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000350the \fB\-d\fP option. If set to an integer, it is equivalent to
351specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000352.IP PYTHONINSPECT
353If this is set to a non-empty string it is equivalent to specifying
354the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000355.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000357the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000358.IP PYTHONVERBOSE
359If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000360the \fB\-v\fP option. If set to an integer, it is equivalent to
361specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000362.SH AUTHOR
363.nf
364Guido van Rossum
Guido van Rossuma7925f11994-01-26 10:20:16 +0000365.PP
Guido van Rossum1378c322000-12-19 03:21:54 +0000366E-mail: guido@python.org
Guido van Rossuma7925f11994-01-26 10:20:16 +0000367.fi
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000368.PP
369And a cast of thousands.
Guido van Rossum74faed21996-07-30 19:27:05 +0000370.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000371Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000372.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000373Documentation: http://www.python.org/doc/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000374.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000375Community website: http://starship.python.net/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000376.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000377Developer resources: http://sourceforge.net/project/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000378.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000379FTP: ftp://ftp.python.org/pub/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000380.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000381Module repository: http://www.vex.net/parnassus/
Guido van Rossum74faed21996-07-30 19:27:05 +0000382.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000383Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000384.SH LICENSING
385Python is distributed under an Open Source license. See the file
386"LICENSE" in the Python source distribution for information on terms &
387conditions for accessing and otherwise using Python and for a
388DISCLAIMER OF ALL WARRANTIES.