blob: 609c2ca147f3a2d8fa9d1fb74e289e10c6b499bc [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
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000141Force stdin, stdout and stderr to be totally unbuffered.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000142.TP
143.B \-v
144Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000145(filename or built-in module) from which it is loaded. When given
146twice, print a message for each file that is checked for when
147searching for a module. Also provides information on module cleanup
148at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000149.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000150.B \-V
151Prints the Python version number of the executable and exits.
152.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000153.BI "\-W " argument
154Warning control. Python sometimes prints warning message to
155.IR sys.stderr .
156A typical warning message has the following form:
157.IB file ":" line ": " category ": " message.
158By default, each warning is printed once for each source line where it
159occurs. This option controls how often warnings are printed.
160Multiple
161.B \-W
162options may be given; when a warning matches more than one
163option, the action for the last matching option is performed.
164Invalid
165.B \-W
166options are ignored (a warning message is printed about invalid
167options when the first warning is issued). Warnings can also be
168controlled from within a Python program using the
169.I warnings
170module.
171
172The simplest form of
173.I argument
174is one of the following
175.I action
176strings (or a unique abbreviation):
177.B ignore
178to ignore all warnings;
179.B default
180to explicitly request the default behavior (printing each warning once
181per source line);
182.B all
183to print a warning each time it occurs (this may generate many
184messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000185line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000186.B module
187to print each warning only only the first time it occurs in each
188module;
189.B once
190to print each warning only the first time it occurs in the program; or
191.B error
192to raise an exception instead of printing a warning message.
193
194The full form of
195.I argument
196is
197.IB action : message : category : module : line.
198Here,
199.I action
200is as explained above but only applies to messages that match the
201remaining fields. Empty fields match all values; trailing empty
202fields may be omitted. The
203.I message
204field matches the start of the warning message printed; this match is
205case-insensitive. The
206.I category
207field matches the warning category. This must be a class name; the
208match test whether the actual warning category of the message is a
209subclass of the specified warning category. The full class name must
210be given. The
211.I module
212field matches the (fully-qualified) module name; this match is
213case-sensitive. The
214.I line
215field matches the line number, where zero matches all line numbers and
216is thus equivalent to an omitted line number.
217.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000218.B \-x
219Skip the first line of the source. This is intended for a DOS
220specific hack only. Warning: the line numbers in error messages will
221be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000222.SH INTERPRETER INTERFACE
223The interpreter interface resembles that of the UNIX shell: when
224called with standard input connected to a tty device, it prompts for
225commands and executes them until an EOF is read; when called with a
226file name argument or with a file as standard input, it reads and
227executes a
228.I script
229from that file;
230when called with
231.B \-c
232.I command,
233it executes the Python statement(s) given as
234.I command.
235Here
236.I command
237may contain multiple statements separated by newlines.
238Leading whitespace is significant in Python statements!
239In non-interactive mode, the entire input is parsed befored it is
240executed.
241.PP
242If available, the script name and additional arguments thereafter are
243passed to the script in the Python variable
244.I sys.argv ,
245which is a list of strings (you must first
246.I import sys
247to be able to access it).
248If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000249.I sys.argv[0]
250is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000251.B \-c
252is used,
253.I sys.argv[0]
254contains the string
255.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000256Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000257are not placed in
258.I sys.argv.
259.PP
260In interactive mode, the primary prompt is `>>>'; the second prompt
261(which appears when a command is not complete) is `...'.
262The prompts can be changed by assignment to
263.I sys.ps1
264or
265.I sys.ps2.
266The interpreter quits when it reads an EOF at a prompt.
267When an unhandled exception occurs, a stack trace is printed and
268control returns to the primary prompt; in non-interactive mode, the
269interpreter exits after printing the stack trace.
270The interrupt signal raises the
271.I Keyboard\%Interrupt
272exception; other UNIX signals are not caught (except that SIGPIPE is
273sometimes ignored, in favor of the
274.I IOError
275exception). Error messages are written to stderr.
276.SH FILES AND DIRECTORIES
277These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000278conventions; ${prefix} and ${exec_prefix} are installation-dependent
279and should be interpreted as for GNU software; they may be the same.
280The default for both is \fI/usr/local\fP.
281.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000282Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000283.PP
284.I ${prefix}/lib/python<version>
285.br
286.I ${exec_prefix}/lib/python<version>
287.RS
288Recommended locations of the directories containing the standard
289modules.
290.RE
291.PP
292.I ${prefix}/include/python<version>
293.br
294.I ${exec_prefix}/include/python<version>
295.RS
296Recommended locations of the directories containing the include files
297needed for developing Python extensions and embedding the
298interpreter.
299.RE
300.IP \fI~/.pythonrc.py\fP
301User-specific initialization file loaded by the \fIuser\fP module;
302not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000303.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000304.IP PYTHONHOME
305Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000306libraries are searched in ${prefix}/lib/python<version> and
307${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000308are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000309\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
310replaces both ${prefix} and ${exec_prefix}. To specify different values
311for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000312.IP PYTHONPATH
313Augments the default search path for module files.
314The format is the same as the shell's $PATH: one or more directory
315pathnames separated by colons.
316Non-existant directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000317The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000318begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000319The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000320If a script argument is given, the directory containing the script is
321inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000322The search path can be manipulated from within a Python program as the
323variable
324.I sys.path .
325.IP PYTHONSTARTUP
326If this is the name of a readable file, the Python commands in that
327file are executed before the first prompt is displayed in interactive
328mode.
329The file is executed in the same name space where interactive commands
330are executed so that objects defined or imported in it can be used
331without qualification in the interactive session.
332You can also change the prompts
333.I sys.ps1
334and
335.I sys.ps2
336in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000337.IP PYTHONY2K
338Set this to a non-empty string to cause the \fItime\fP module to
339require dates specified as strings to include 4-digit years, otherwise
3402-digit years are converted based on rules described in the \fItime\fP
341module documnetation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000342.IP PYTHONOPTIMIZE
343If this is set to a non-empty string it is equivalent to specifying
344the \fB\-O\fP option. If set to an integer, it is equivalent to
345specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000346.IP PYTHONDEBUG
347If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000348the \fB\-d\fP option. If set to an integer, it is equivalent to
349specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000350.IP PYTHONINSPECT
351If this is set to a non-empty string it is equivalent to specifying
352the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000353.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000354If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000355the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000356.IP PYTHONVERBOSE
357If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000358the \fB\-v\fP option. If set to an integer, it is equivalent to
359specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000360.SH AUTHOR
361.nf
362Guido van Rossum
Guido van Rossuma7925f11994-01-26 10:20:16 +0000363.PP
Guido van Rossum1378c322000-12-19 03:21:54 +0000364E-mail: guido@python.org
Guido van Rossuma7925f11994-01-26 10:20:16 +0000365.fi
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000366.PP
367And a cast of thousands.
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
Fred Drakebd2e3b02001-07-26 21:25:58 +0000371Documentation: http://www.python.org/doc/
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
Fred Drakebd2e3b02001-07-26 21:25:58 +0000375Developer resources: http://sourceforge.net/project/python/
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.