blob: 9a406a8e95a4f3cbc1f7eb5b283b4c2b62329d39 [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]
Guido van Rossumb674baf2001-09-05 18:55:34 +000029.br
30 [
Matthias Klosec8b16f82010-01-31 16:14:37 +000031.B \-O
32]
33[
34.B \-O0
35]
36[
Guido van Rossumb674baf2001-09-05 18:55:34 +000037.B -Q
38.I argument
Guido van Rossum4cf4de51997-09-08 04:06:15 +000039]
40[
Matthias Klosec8b16f82010-01-31 16:14:37 +000041.B \-s
42]
43[
Guido van Rossumb674baf2001-09-05 18:55:34 +000044.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000045]
46[
Guido van Rossumef5bca31994-05-03 14:15:32 +000047.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000048]
Guido van Rossumb674baf2001-09-05 18:55:34 +000049.br
50 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000051.B \-v
52]
Guido van Rossum07c44c71998-04-10 19:46:00 +000053[
Barry Warsaw64569372000-09-15 18:39:09 +000054.B \-V
55]
Guido van Rossum1378c322000-12-19 03:21:54 +000056[
57.B \-W
58.I argument
59]
Guido van Rossumb674baf2001-09-05 18:55:34 +000060[
61.B \-x
62]
Matthias Klosec8b16f82010-01-31 16:14:37 +000063[
64.B \-?
65]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000066.br
67 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000068.B \-c
69.I command
70|
71.I script
72|
73\-
74]
75[
76.I arguments
77]
78.SH DESCRIPTION
79Python is an interpreted, interactive, object-oriented programming
80language that combines remarkable power with very clear syntax.
81For an introduction to programming in Python you are referred to the
82Python Tutorial.
83The Python Library Reference documents built-in and standard types,
84constants, functions and modules.
85Finally, the Python Reference Manual describes the syntax and
86semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000087(These documents may be located via the
88.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000089below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000090.PP
91Python's basic power can be extended with your own modules written in
92C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +000093On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +000094Python is also adaptable as an extension language for existing
95applications.
96See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +000097.PP
98Documentation for installed Python modules and packages can be
99viewed by running the
100.B pydoc
101program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000102.SH COMMAND LINE OPTIONS
103.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000104.B \-B
105Don't write
106.I .py[co]
107files on import. See also PYTHONDONTWRITEBYTECODE.
108.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000109.BI "\-c " command
110Specify the command to execute (see next section).
111This terminates the option list (following options are passed as
112arguments to the command).
113.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000114.B \-d
115Turn on parser debugging output (for wizards only, depending on
116compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000117.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000118.B \-E
119Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
120the behavior of the interpreter.
121.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000122.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000123Prints the usage for the interpreter executable and exits.
124.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000125.B \-i
126When a script is passed as first argument or the \fB\-c\fP option is
127used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000128command. It does not read the $PYTHONSTARTUP file. This can be
129useful to inspect global variables or a stack trace when a script
130raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000131.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000132.BI "\-m " module-name
133Searches
134.I sys.path
135for the named module and runs the corresponding
136.I .py
137file as a script.
138.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000139.B \-O
140Turn on basic optimizations. This changes the filename extension for
141compiled (bytecode) files from
142.I .pyc
Fred Drake4c9be9d1999-08-20 13:10:20 +0000143to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000144.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000145.B \-O0
146Discard docstrings in addition to the \fB-O\fP optimizations.
147.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000148.BI "\-Q " argument
149Division control; see PEP 238. The argument must be one of "old" (the
150default, int/int and long/long return an int or long), "new" (new
151division semantics, i.e. int/int and long/long returns a float),
152"warn" (old division semantics with a warning for int/int and
153long/long), or "warnall" (old division semantics with a warning for
154all use of the division operator). For a use of "warnall", see the
155Tools/scripts/fixdiv.py script.
156.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000157.B \-s
158Don't add user site directory to sys.path.
159.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000160.B \-S
161Disable the import of the module
162.I site
163and the site-dependent manipulations of
164.I sys.path
165that it entails.
166.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000167.B \-u
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000168Force stdin, stdout and stderr to be totally unbuffered. On systems
169where it matters, also put stdin, stdout and stderr in binary mode.
Neal Norwitz70967602006-03-17 08:29:44 +0000170Note that there is internal buffering in readlines() and
Sjoerd Mullenderb6434f22002-08-09 13:37:31 +0000171file-object iterators ("for line in sys.stdin") which is not
172influenced by this option. To work around this, you will want to use
173"sys.stdin.readline()" inside a "while 1:" loop.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000174.TP
175.B \-v
176Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000177(filename or built-in module) from which it is loaded. When given
178twice, print a message for each file that is checked for when
179searching for a module. Also provides information on module cleanup
180at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000181.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000182.B \-V ", " \-\-version
Barry Warsaw64569372000-09-15 18:39:09 +0000183Prints the Python version number of the executable and exits.
184.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000185.BI "\-W " argument
186Warning control. Python sometimes prints warning message to
187.IR sys.stderr .
188A typical warning message has the following form:
189.IB file ":" line ": " category ": " message.
190By default, each warning is printed once for each source line where it
191occurs. This option controls how often warnings are printed.
192Multiple
193.B \-W
194options may be given; when a warning matches more than one
195option, the action for the last matching option is performed.
196Invalid
197.B \-W
198options are ignored (a warning message is printed about invalid
199options when the first warning is issued). Warnings can also be
200controlled from within a Python program using the
201.I warnings
202module.
203
204The simplest form of
205.I argument
206is one of the following
207.I action
208strings (or a unique abbreviation):
209.B ignore
210to ignore all warnings;
211.B default
212to explicitly request the default behavior (printing each warning once
213per source line);
214.B all
215to print a warning each time it occurs (this may generate many
216messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000217line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000218.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000219to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000220module;
221.B once
222to print each warning only the first time it occurs in the program; or
223.B error
224to raise an exception instead of printing a warning message.
225
226The full form of
227.I argument
228is
229.IB action : message : category : module : line.
230Here,
231.I action
232is as explained above but only applies to messages that match the
233remaining fields. Empty fields match all values; trailing empty
234fields may be omitted. The
235.I message
236field matches the start of the warning message printed; this match is
237case-insensitive. The
238.I category
239field matches the warning category. This must be a class name; the
240match test whether the actual warning category of the message is a
241subclass of the specified warning category. The full class name must
242be given. The
243.I module
244field matches the (fully-qualified) module name; this match is
245case-sensitive. The
246.I line
247field matches the line number, where zero matches all line numbers and
248is thus equivalent to an omitted line number.
249.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000250.B \-x
251Skip the first line of the source. This is intended for a DOS
252specific hack only. Warning: the line numbers in error messages will
253be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000254.SH INTERPRETER INTERFACE
255The interpreter interface resembles that of the UNIX shell: when
256called with standard input connected to a tty device, it prompts for
257commands and executes them until an EOF is read; when called with a
258file name argument or with a file as standard input, it reads and
259executes a
260.I script
261from that file;
262when called with
263.B \-c
264.I command,
265it executes the Python statement(s) given as
266.I command.
267Here
268.I command
269may contain multiple statements separated by newlines.
270Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000271In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000272executed.
273.PP
274If available, the script name and additional arguments thereafter are
275passed to the script in the Python variable
276.I sys.argv ,
277which is a list of strings (you must first
278.I import sys
279to be able to access it).
280If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000281.I sys.argv[0]
282is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000283.B \-c
284is used,
285.I sys.argv[0]
286contains the string
287.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000288Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000289are not placed in
290.I sys.argv.
291.PP
292In interactive mode, the primary prompt is `>>>'; the second prompt
293(which appears when a command is not complete) is `...'.
294The prompts can be changed by assignment to
295.I sys.ps1
296or
297.I sys.ps2.
298The interpreter quits when it reads an EOF at a prompt.
299When an unhandled exception occurs, a stack trace is printed and
300control returns to the primary prompt; in non-interactive mode, the
301interpreter exits after printing the stack trace.
302The interrupt signal raises the
303.I Keyboard\%Interrupt
304exception; other UNIX signals are not caught (except that SIGPIPE is
305sometimes ignored, in favor of the
306.I IOError
307exception). Error messages are written to stderr.
308.SH FILES AND DIRECTORIES
309These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000310conventions; ${prefix} and ${exec_prefix} are installation-dependent
311and should be interpreted as for GNU software; they may be the same.
312The default for both is \fI/usr/local\fP.
313.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000314Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000315.PP
316.I ${prefix}/lib/python<version>
317.br
318.I ${exec_prefix}/lib/python<version>
319.RS
320Recommended locations of the directories containing the standard
321modules.
322.RE
323.PP
324.I ${prefix}/include/python<version>
325.br
326.I ${exec_prefix}/include/python<version>
327.RS
328Recommended locations of the directories containing the include files
329needed for developing Python extensions and embedding the
330interpreter.
331.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000332.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000333.IP PYTHONHOME
334Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000335libraries are searched in ${prefix}/lib/python<version> and
336${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000337are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000338\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
339replaces both ${prefix} and ${exec_prefix}. To specify different values
340for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000341.IP PYTHONPATH
342Augments the default search path for module files.
343The format is the same as the shell's $PATH: one or more directory
344pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000345Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000346The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000347begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000348The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000349If a script argument is given, the directory containing the script is
350inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000351The search path can be manipulated from within a Python program as the
352variable
353.I sys.path .
354.IP PYTHONSTARTUP
355If this is the name of a readable file, the Python commands in that
356file are executed before the first prompt is displayed in interactive
357mode.
358The file is executed in the same name space where interactive commands
359are executed so that objects defined or imported in it can be used
360without qualification in the interactive session.
361You can also change the prompts
362.I sys.ps1
363and
364.I sys.ps2
365in this file.
Fred Drakebd2e3b02001-07-26 21:25:58 +0000366.IP PYTHONY2K
367Set this to a non-empty string to cause the \fItime\fP module to
368require dates specified as strings to include 4-digit years, otherwise
3692-digit years are converted based on rules described in the \fItime\fP
Andrew M. Kuchlingb2cb37f2002-05-09 14:33:18 +0000370module documentation.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000371.IP PYTHONOPTIMIZE
372If this is set to a non-empty string it is equivalent to specifying
373the \fB\-O\fP option. If set to an integer, it is equivalent to
374specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000375.IP PYTHONDEBUG
376If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000377the \fB\-d\fP option. If set to an integer, it is equivalent to
378specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000379.IP PYTHONDONTWRITEBYTECODE
380If this is set to a non-empty string it is equivalent to specifying
381the \fB\-B\fP option (don't try to write
382.I .py[co]
383files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000384.IP PYTHONINSPECT
385If this is set to a non-empty string it is equivalent to specifying
386the \fB\-i\fP option.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000387.IP PYTHONNOUSERSITE
388If this is set to a non-empty string it is equivalent to specifying
389the \fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000390.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000391If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000392the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000393.IP PYTHONVERBOSE
394If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000395the \fB\-v\fP option. If set to an integer, it is equivalent to
396specifying \fB\-v\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000397.SH AUTHOR
Andrew M. Kuchling6f593252004-10-07 12:27:31 +0000398The Python Software Foundation: http://www.python.org/psf
Guido van Rossum74faed21996-07-30 19:27:05 +0000399.SH INTERNET RESOURCES
Fred Drakebd2e3b02001-07-26 21:25:58 +0000400Main website: http://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000401.br
Benjamin Peterson6aa7c8c2009-09-13 02:23:12 +0000402Documentation: http://docs.python.org/py3k/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000403.br
Andrew M. Kuchling895f2452004-10-07 12:23:12 +0000404Developer resources: http://www.python.org/dev/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000405.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000406Downloads: http://python.org/download/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000407.br
Benjamin Peterson25a8dd72009-09-13 02:22:00 +0000408Module repository: http://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000409.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000410Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000411.SH LICENSING
412Python is distributed under an Open Source license. See the file
413"LICENSE" in the Python source distribution for information on terms &
414conditions for accessing and otherwise using Python and for a
415DISCLAIMER OF ALL WARRANTIES.