blob: 5d4c6176cfb7fc4298cbf0cae7d96df0cccda613 [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
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000141Force stdin, stdout and stderr to be totally unbuffered. On systems
142where it matters, also put stdin, stdout and stderr in binary mode.
143Note that there is internal buffering in xreadlines(), readlines() and
144file-object iterators ("for line in sys.stdin") which is not
145influenced by this option. To work around this, you will want to use
146"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000147.TP
148.B \-v
149Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000150(filename or built-in module) from which it is loaded. When given
151twice, print a message for each file that is checked for when
152searching for a module. Also provides information on module cleanup
153at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000154.TP
Barry Warsaw64569372000-09-15 18:39:09 +0000155.B \-V
156Prints the Python version number of the executable and exits.
157.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000158.BI "\-W " argument
159Warning control. Python sometimes prints warning message to
160.IR sys.stderr .
161A typical warning message has the following form:
162.IB file ":" line ": " category ": " message.
163By default, each warning is printed once for each source line where it
164occurs. This option controls how often warnings are printed.
165Multiple
166.B \-W
167options may be given; when a warning matches more than one
168option, the action for the last matching option is performed.
169Invalid
170.B \-W
171options are ignored (a warning message is printed about invalid
172options when the first warning is issued). Warnings can also be
173controlled from within a Python program using the
174.I warnings
175module.
176
177The simplest form of
178.I argument
179is one of the following
180.I action
181strings (or a unique abbreviation):
182.B ignore
183to ignore all warnings;
184.B default
185to explicitly request the default behavior (printing each warning once
186per source line);
187.B all
188to print a warning each time it occurs (this may generate many
189messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000190line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000191.B module
192to print each warning only only the first time it occurs in each
193module;
194.B once
195to print each warning only the first time it occurs in the program; or
196.B error
197to raise an exception instead of printing a warning message.
198
199The full form of
200.I argument
201is
202.IB action : message : category : module : line.
203Here,
204.I action
205is as explained above but only applies to messages that match the
206remaining fields. Empty fields match all values; trailing empty
207fields may be omitted. The
208.I message
209field matches the start of the warning message printed; this match is
210case-insensitive. The
211.I category
212field matches the warning category. This must be a class name; the
213match test whether the actual warning category of the message is a
214subclass of the specified warning category. The full class name must
215be given. The
216.I module
217field matches the (fully-qualified) module name; this match is
218case-sensitive. The
219.I line
220field matches the line number, where zero matches all line numbers and
221is thus equivalent to an omitted line number.
222.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000223.B \-x
224Skip the first line of the source. This is intended for a DOS
225specific hack only. Warning: the line numbers in error messages will
226be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000227.SH INTERPRETER INTERFACE
228The interpreter interface resembles that of the UNIX shell: when
229called with standard input connected to a tty device, it prompts for
230commands and executes them until an EOF is read; when called with a
231file name argument or with a file as standard input, it reads and
232executes a
233.I script
234from that file;
235when called with
236.B \-c
237.I command,
238it executes the Python statement(s) given as
239.I command.
240Here
241.I command
242may contain multiple statements separated by newlines.
243Leading whitespace is significant in Python statements!
244In non-interactive mode, the entire input is parsed befored it is
245executed.
246.PP
247If available, the script name and additional arguments thereafter are
248passed to the script in the Python variable
249.I sys.argv ,
250which is a list of strings (you must first
251.I import sys
252to be able to access it).
253If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000254.I sys.argv[0]
255is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000256.B \-c
257is used,
258.I sys.argv[0]
259contains the string
260.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000261Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000262are not placed in
263.I sys.argv.
264.PP
265In interactive mode, the primary prompt is `>>>'; the second prompt
266(which appears when a command is not complete) is `...'.
267The prompts can be changed by assignment to
268.I sys.ps1
269or
270.I sys.ps2.
271The interpreter quits when it reads an EOF at a prompt.
272When an unhandled exception occurs, a stack trace is printed and
273control returns to the primary prompt; in non-interactive mode, the
274interpreter exits after printing the stack trace.
275The interrupt signal raises the
276.I Keyboard\%Interrupt
277exception; other UNIX signals are not caught (except that SIGPIPE is
278sometimes ignored, in favor of the
279.I IOError
280exception). Error messages are written to stderr.
281.SH FILES AND DIRECTORIES
282These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000283conventions; ${prefix} and ${exec_prefix} are installation-dependent
284and should be interpreted as for GNU software; they may be the same.
285The default for both is \fI/usr/local\fP.
286.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000287Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000288.PP
289.I ${prefix}/lib/python<version>
290.br
291.I ${exec_prefix}/lib/python<version>
292.RS
293Recommended locations of the directories containing the standard
294modules.
295.RE
296.PP
297.I ${prefix}/include/python<version>
298.br
299.I ${exec_prefix}/include/python<version>
300.RS
301Recommended locations of the directories containing the include files
302needed for developing Python extensions and embedding the
303interpreter.
304.RE
305.IP \fI~/.pythonrc.py\fP
306User-specific initialization file loaded by the \fIuser\fP module;
307not used by default or by most applications.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000308.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000309.IP PYTHONHOME
310Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000311libraries are searched in ${prefix}/lib/python<version> and
312${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000313are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000314\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
315replaces both ${prefix} and ${exec_prefix}. To specify different values
316for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000317.IP PYTHONPATH
318Augments the default search path for module files.
319The format is the same as the shell's $PATH: one or more directory
320pathnames separated by colons.
321Non-existant directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000322The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000323begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000324The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000325If a script argument is given, the directory containing the script is
326inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000327The search path can be manipulated from within a Python program as the
328variable
329.I sys.path .
330.IP PYTHONSTARTUP
331If this is the name of a readable file, the Python commands in that
332file are executed before the first prompt is displayed in interactive
333mode.
334The file is executed in the same name space where interactive commands
335are executed so that objects defined or imported in it can be used
336without qualification in the interactive session.
337You can also change the prompts
338.I sys.ps1
339and
340.I sys.ps2
341in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000342.IP PYTHONY2K
343Set this to a non-empty string to cause the \fItime\fP module to
344require dates specified as strings to include 4-digit years, otherwise
3452-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000346module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000347.IP PYTHONOPTIMIZE
348If this is set to a non-empty string it is equivalent to specifying
349the \fB\-O\fP option. If set to an integer, it is equivalent to
350specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000351.IP PYTHONDEBUG
352If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000353the \fB\-d\fP option. If set to an integer, it is equivalent to
354specifying \fB\-d\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000355.IP PYTHONINSPECT
356If this is set to a non-empty string it is equivalent to specifying
357the \fB\-i\fP option.
Guido van Rossumef5bca31994-05-03 14:15:32 +0000358.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000359If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000360the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000361.IP PYTHONVERBOSE
362If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000363the \fB\-v\fP option. If set to an integer, it is equivalent to
364specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000365.SH AUTHOR
366.nf
367Guido van Rossum
Guido van Rossuma7925f11994-01-26 10:20:16 +0000368.PP
Guido van Rossum1378c322000-12-19 03:21:54 +0000369E-mail: guido@python.org
Guido van Rossuma7925f11994-01-26 10:20:16 +0000370.fi
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000371.PP
372And a cast of thousands.
Guido van Rossum74faed21996-07-30 19:27:05 +0000373.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000374Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000375.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000376Documentation: http://www.python.org/doc/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000377.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000378Community website: http://starship.python.net/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000379.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000380Developer resources: http://sourceforge.net/project/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000381.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000382FTP: ftp://ftp.python.org/pub/python/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000383.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000384Module repository: http://www.vex.net/parnassus/
Guido van Rossum74faed21996-07-30 19:27:05 +0000385.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000386Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000387.SH LICENSING
388Python is distributed under an Open Source license. See the file
389"LICENSE" in the Python source distribution for information on terms &
390conditions for accessing and otherwise using Python and for a
391DISCLAIMER OF ALL WARRANTIES.