blob: 53b77fcd1bc2120cf31a7278c6fe6284e667ebb8 [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
Benjamin Peterson5f28b7b2009-03-26 21:49:58 +00003.\" To view this file while editing, run it through groff:
4.\" groff -Tascii -man python.man | less
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00005
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[
Matthias Klosec8b16f82010-01-31 16:14:37 +000011.B \-B
12]
13[
Guido van Rossuma7925f11994-01-26 10:20:16 +000014.B \-d
15]
16[
Guido van Rossumb674baf2001-09-05 18:55:34 +000017.B \-E
18]
19[
20.B \-h
21]
22[
Guido van Rossuma7925f11994-01-26 10:20:16 +000023.B \-i
24]
25[
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000026.B \-m
27.I module-name
28]
Georg Brandl9d871192010-12-04 10:47:18 +000029[
30.B \-q
31]
Guido van Rossumb674baf2001-09-05 18:55:34 +000032.br
33 [
Matthias Klosec8b16f82010-01-31 16:14:37 +000034.B \-O
35]
36[
37.B \-O0
38]
39[
Guido van Rossumb674baf2001-09-05 18:55:34 +000040.B -Q
41.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000042]
43[
Matthias Klosec8b16f82010-01-31 16:14:37 +000044.B \-s
45]
46[
Guido van Rossumb674baf2001-09-05 18:55:34 +000047.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000048]
49[
Guido van Rossumef5bca31994-05-03 14:15:32 +000050.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000051]
Guido van Rossumb674baf2001-09-05 18:55:34 +000052.br
53 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000054.B \-v
55]
Guido van Rossum07c44c71998-04-10 19:46:00 +000056[
Barry Warsaw64569372000-09-15 18:39:09 +000057.B \-V
58]
Guido van Rossum1378c322000-12-19 03:21:54 +000059[
60.B \-W
61.I argument
62]
Guido van Rossumb674baf2001-09-05 18:55:34 +000063[
64.B \-x
65]
Matthias Klosec8b16f82010-01-31 16:14:37 +000066[
67.B \-?
68]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000069.br
70 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000071.B \-c
72.I command
73|
74.I script
75|
76\-
77]
78[
79.I arguments
80]
81.SH DESCRIPTION
82Python is an interpreted, interactive, object-oriented programming
83language that combines remarkable power with very clear syntax.
84For an introduction to programming in Python you are referred to the
85Python Tutorial.
86The Python Library Reference documents built-in and standard types,
87constants, functions and modules.
88Finally, the Python Reference Manual describes the syntax and
89semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000090(These documents may be located via the
91.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000092below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000093.PP
94Python's basic power can be extended with your own modules written in
95C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000096On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000097Python is also adaptable as an extension language for existing
98applications.
99See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000100.PP
101Documentation for installed Python modules and packages can be
102viewed by running the
103.B pydoc
104program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000105.SH COMMAND LINE OPTIONS
106.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000107.B \-B
108Don't write
109.I .py[co]
110files on import. See also PYTHONDONTWRITEBYTECODE.
111.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000112.BI "\-c " command
113Specify the command to execute (see next section).
114This terminates the option list (following options are passed as
115arguments to the command).
116.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000117.B \-d
118Turn on parser debugging output (for wizards only, depending on
119compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000120.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000121.B \-E
122Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
123the behavior of the interpreter.
124.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000125.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000126Prints the usage for the interpreter executable and exits.
127.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000128.B \-i
129When a script is passed as first argument or the \fB\-c\fP option is
130used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000131command. It does not read the $PYTHONSTARTUP file. This can be
132useful to inspect global variables or a stack trace when a script
133raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000134.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000135.BI "\-m " module-name
136Searches
137.I sys.path
138for the named module and runs the corresponding
139.I .py
140file as a script.
141.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000142.B \-O
143Turn on basic optimizations. This changes the filename extension for
144compiled (bytecode) files from
145.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000146to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000147.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000148.B \-O0
149Discard docstrings in addition to the \fB-O\fP optimizations.
150.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000151.B \-q
152Do not print the version and copyright messages. These messages are
153also suppressed in non-interactive mode.
154.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000155.BI "\-Q " argument
156Division control; see PEP 238. The argument must be one of "old" (the
157default, int/int and long/long return an int or long), "new" (new
158division semantics, i.e. int/int and long/long returns a float),
159"warn" (old division semantics with a warning for int/int and
160long/long), or "warnall" (old division semantics with a warning for
161all use of the division operator). For a use of "warnall", see the
162Tools/scripts/fixdiv.py script.
163.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000164.B \-s
165Don't add user site directory to sys.path.
166.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000167.B \-S
168Disable the import of the module
169.I site
170and the site-dependent manipulations of
171.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100172that it entails. Also disable these manipulations if
173.I site
174is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000175.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000176.B \-u
Georg Brandl379299c2010-04-02 08:47:07 +0000177Force the binary I/O layers of stdin, stdout and stderr to be unbuffered.
178The text I/O layer will still be line-buffered.
179.\" Note that there is internal buffering in readlines() and
180.\" file-object iterators ("for line in sys.stdin") which is not
181.\" influenced by this option. To work around this, you will want to use
182.\" "sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000183.TP
184.B \-v
185Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000186(filename or built-in module) from which it is loaded. When given
187twice, print a message for each file that is checked for when
188searching for a module. Also provides information on module cleanup
189at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000190.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000191.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000192Prints the Python version number of the executable and exits.
193.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000194.BI "\-W " argument
195Warning control. Python sometimes prints warning message to
196.IR sys.stderr .
197A typical warning message has the following form:
198.IB file ":" line ": " category ": " message.
199By default, each warning is printed once for each source line where it
200occurs. This option controls how often warnings are printed.
201Multiple
202.B \-W
203options may be given; when a warning matches more than one
204option, the action for the last matching option is performed.
205Invalid
206.B \-W
207options are ignored (a warning message is printed about invalid
208options when the first warning is issued). Warnings can also be
209controlled from within a Python program using the
210.I warnings
211module.
212
213The simplest form of
214.I argument
215is one of the following
216.I action
217strings (or a unique abbreviation):
218.B ignore
219to ignore all warnings;
220.B default
221to explicitly request the default behavior (printing each warning once
222per source line);
223.B all
224to print a warning each time it occurs (this may generate many
225messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000226line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000227.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000228to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000229module;
230.B once
231to print each warning only the first time it occurs in the program; or
232.B error
233to raise an exception instead of printing a warning message.
234
235The full form of
236.I argument
237is
238.IB action : message : category : module : line.
239Here,
240.I action
241is as explained above but only applies to messages that match the
242remaining fields. Empty fields match all values; trailing empty
243fields may be omitted. The
244.I message
245field matches the start of the warning message printed; this match is
246case-insensitive. The
247.I category
248field matches the warning category. This must be a class name; the
249match test whether the actual warning category of the message is a
250subclass of the specified warning category. The full class name must
251be given. The
252.I module
253field matches the (fully-qualified) module name; this match is
254case-sensitive. The
255.I line
256field matches the line number, where zero matches all line numbers and
257is thus equivalent to an omitted line number.
258.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000259.B \-x
260Skip the first line of the source. This is intended for a DOS
261specific hack only. Warning: the line numbers in error messages will
262be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000263.SH INTERPRETER INTERFACE
264The interpreter interface resembles that of the UNIX shell: when
265called with standard input connected to a tty device, it prompts for
266commands and executes them until an EOF is read; when called with a
267file name argument or with a file as standard input, it reads and
268executes a
269.I script
270from that file;
271when called with
272.B \-c
273.I command,
274it executes the Python statement(s) given as
275.I command.
276Here
277.I command
278may contain multiple statements separated by newlines.
279Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000280In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000281executed.
282.PP
283If available, the script name and additional arguments thereafter are
284passed to the script in the Python variable
285.I sys.argv ,
286which is a list of strings (you must first
287.I import sys
288to be able to access it).
289If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000290.I sys.argv[0]
291is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000292.B \-c
293is used,
294.I sys.argv[0]
295contains the string
296.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000297Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000298are not placed in
299.I sys.argv.
300.PP
301In interactive mode, the primary prompt is `>>>'; the second prompt
302(which appears when a command is not complete) is `...'.
303The prompts can be changed by assignment to
304.I sys.ps1
305or
306.I sys.ps2.
307The interpreter quits when it reads an EOF at a prompt.
308When an unhandled exception occurs, a stack trace is printed and
309control returns to the primary prompt; in non-interactive mode, the
310interpreter exits after printing the stack trace.
311The interrupt signal raises the
312.I Keyboard\%Interrupt
313exception; other UNIX signals are not caught (except that SIGPIPE is
314sometimes ignored, in favor of the
315.I IOError
316exception). Error messages are written to stderr.
317.SH FILES AND DIRECTORIES
318These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000319conventions; ${prefix} and ${exec_prefix} are installation-dependent
320and should be interpreted as for GNU software; they may be the same.
321The default for both is \fI/usr/local\fP.
322.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000323Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000324.PP
325.I ${prefix}/lib/python<version>
326.br
327.I ${exec_prefix}/lib/python<version>
328.RS
329Recommended locations of the directories containing the standard
330modules.
331.RE
332.PP
333.I ${prefix}/include/python<version>
334.br
335.I ${exec_prefix}/include/python<version>
336.RS
337Recommended locations of the directories containing the include files
338needed for developing Python extensions and embedding the
339interpreter.
340.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000341.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000342.IP PYTHONHOME
343Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000344libraries are searched in ${prefix}/lib/python<version> and
345${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000346are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000347\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
348replaces both ${prefix} and ${exec_prefix}. To specify different values
349for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000350.IP PYTHONPATH
351Augments the default search path for module files.
352The format is the same as the shell's $PATH: one or more directory
353pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000354Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000355The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000356begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000357The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000358If a script argument is given, the directory containing the script is
359inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000360The search path can be manipulated from within a Python program as the
361variable
362.I sys.path .
363.IP PYTHONSTARTUP
364If this is the name of a readable file, the Python commands in that
365file are executed before the first prompt is displayed in interactive
366mode.
367The file is executed in the same name space where interactive commands
368are executed so that objects defined or imported in it can be used
369without qualification in the interactive session.
370You can also change the prompts
371.I sys.ps1
372and
373.I sys.ps2
374in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000375.IP PYTHONY2K
376Set this to a non-empty string to cause the \fItime\fP module to
377require dates specified as strings to include 4-digit years, otherwise
3782-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000379module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000380.IP PYTHONOPTIMIZE
381If this is set to a non-empty string it is equivalent to specifying
382the \fB\-O\fP option. If set to an integer, it is equivalent to
383specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000384.IP PYTHONDEBUG
385If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000386the \fB\-d\fP option. If set to an integer, it is equivalent to
387specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000388.IP PYTHONDONTWRITEBYTECODE
389If this is set to a non-empty string it is equivalent to specifying
390the \fB\-B\fP option (don't try to write
391.I .py[co]
392files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000393.IP PYTHONINSPECT
394If this is set to a non-empty string it is equivalent to specifying
395the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000396.IP PYTHONIOENCODING
397If this is set before running the interpreter, it overrides the encoding used
398for stdin/stdout/stderr, in the syntax
399.IB encodingname ":" errorhandler
400The
401.IB errorhandler
402part is optional and has the same meaning as in str.encode. For stderr, the
403.IB errorhandler
404 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000405.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000406If this is set to a non-empty string it is equivalent to specifying the
407\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000408.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000409If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000410the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000411.IP PYTHONVERBOSE
412If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000413the \fB\-v\fP option. If set to an integer, it is equivalent to
414specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000415.IP PYTHONWARNINGS
416If this is set to a comma-separated string it is equivalent to
417specifying the \fB\-W\fP option for each separate value.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000418.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000419The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000420.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000421Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000422.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000423Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000424.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000425Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000426.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000427Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000428.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000429Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000430.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000431Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000432.SH LICENSING
433Python is distributed under an Open Source license. See the file
434"LICENSE" in the Python source distribution for information on terms &
435conditions for accessing and otherwise using Python and for a
436DISCLAIMER OF ALL WARRANTIES.