Merged revisions 72690 via svnmerge from
[python/dscho.git] / Misc / python.man
blob3c7d6067e1beaeff7462e0c272368320abc25079
1 .TH PYTHON "1" "$Date$"
3 .\" To view this file while editing, run it through groff:
4 .\"   groff -Tascii -man python.man | less
6 .SH NAME
7 python \- an interpreted, interactive, object-oriented programming language
8 .SH SYNOPSIS
9 .B python
11 .B \-d
14 .B \-E
17 .B \-h
20 .B \-i
23 .B \-m 
24 .I module-name
27 .B \-O
29 .br
30        [
31 .B -Q
32 .I argument
35 .B \-S
38 .B \-u
40 .br
41        [
42 .B \-v
45 .B \-V
48 .B \-W
49 .I argument
52 .B \-x
54 .br
55        [
56 .B \-c
57 .I command
59 .I script
64 .I arguments
66 .SH DESCRIPTION
67 Python is an interpreted, interactive, object-oriented programming
68 language that combines remarkable power with very clear syntax.
69 For an introduction to programming in Python you are referred to the
70 Python Tutorial.
71 The Python Library Reference documents built-in and standard types,
72 constants, functions and modules.
73 Finally, the Python Reference Manual describes the syntax and
74 semantics of the core language in (perhaps too) much detail.
75 (These documents may be located via the
76 .B "INTERNET RESOURCES"
77 below; they may be installed on your system as well.)
78 .PP
79 Python's basic power can be extended with your own modules written in
80 C or C++.
81 On most systems such modules may be dynamically loaded.
82 Python is also adaptable as an extension language for existing
83 applications.
84 See the internal documentation for hints.
85 .PP
86 Documentation for installed Python modules and packages can be 
87 viewed by running the 
88 .B pydoc
89 program.  
90 .SH COMMAND LINE OPTIONS
91 .TP
92 .BI "\-c " command
93 Specify the command to execute (see next section).
94 This terminates the option list (following options are passed as
95 arguments to the command).
96 .TP
97 .B \-d
98 Turn on parser debugging output (for wizards only, depending on
99 compilation options).
101 .B \-E
102 Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
103 the behavior of the interpreter.
105 .B \-h
106 Prints the usage for the interpreter executable and exits.
108 .B \-i
109 When a script is passed as first argument or the \fB\-c\fP option is
110 used, enter interactive mode after executing the script or the
111 command.  It does not read the $PYTHONSTARTUP file.  This can be
112 useful to inspect global variables or a stack trace when a script
113 raises an exception.
115 .BI "\-m " module-name
116 Searches 
117 .I sys.path 
118 for the named module and runs the corresponding 
119 .I .py 
120 file as a script.
122 .B \-O
123 Turn on basic optimizations.  This changes the filename extension for
124 compiled (bytecode) files from
125 .I .pyc
126 to \fI.pyo\fP.  Given twice, causes docstrings to be discarded.
128 .BI "\-Q " argument
129 Division control; see PEP 238.  The argument must be one of "old" (the
130 default, int/int and long/long return an int or long), "new" (new
131 division semantics, i.e. int/int and long/long returns a float),
132 "warn" (old division semantics with a warning for int/int and
133 long/long), or "warnall" (old division semantics with a warning for
134 all use of the division operator).  For a use of "warnall", see the
135 Tools/scripts/fixdiv.py script.
137 .B \-S
138 Disable the import of the module
139 .I site
140 and the site-dependent manipulations of
141 .I sys.path
142 that it entails.
144 .B \-u
145 Force stdin, stdout and stderr to be totally unbuffered.  On systems
146 where it matters, also put stdin, stdout and stderr in binary mode.
147 Note that there is internal buffering in readlines() and
148 file-object iterators ("for line in sys.stdin") which is not
149 influenced by this option.  To work around this, you will want to use
150 "sys.stdin.readline()" inside a "while 1:" loop.
152 .B \-v
153 Print a message each time a module is initialized, showing the place
154 (filename or built-in module) from which it is loaded.  When given
155 twice, print a message for each file that is checked for when 
156 searching for a module.  Also provides information on module cleanup
157 at exit.
159 .B \-V
160 Prints the Python version number of the executable and exits.
162 .BI "\-W " argument
163 Warning control.  Python sometimes prints warning message to
164 .IR sys.stderr .
165 A typical warning message has the following form:
166 .IB file ":" line ": " category ": " message.
167 By default, each warning is printed once for each source line where it
168 occurs.  This option controls how often warnings are printed.
169 Multiple
170 .B \-W
171 options may be given; when a warning matches more than one
172 option, the action for the last matching option is performed.
173 Invalid
174 .B \-W
175 options are ignored (a warning message is printed about invalid
176 options when the first warning is issued).  Warnings can also be
177 controlled from within a Python program using the
178 .I warnings
179 module.
181 The simplest form of
182 .I argument
183 is one of the following
184 .I action
185 strings (or a unique abbreviation):
186 .B ignore
187 to ignore all warnings;
188 .B default
189 to explicitly request the default behavior (printing each warning once
190 per source line);
191 .B all
192 to print a warning each time it occurs (this may generate many
193 messages if a warning is triggered repeatedly for the same source
194 line, such as inside a loop);
195 .B module
196 to print each warning only only the first time it occurs in each
197 module;
198 .B once
199 to print each warning only the first time it occurs in the program; or
200 .B error
201 to raise an exception instead of printing a warning message.
203 The full form of
204 .I argument
206 .IB action : message : category : module : line.
207 Here,
208 .I action
209 is as explained above but only applies to messages that match the
210 remaining fields.  Empty fields match all values; trailing empty
211 fields may be omitted.  The
212 .I message
213 field matches the start of the warning message printed; this match is
214 case-insensitive.  The
215 .I category
216 field matches the warning category.  This must be a class name; the
217 match test whether the actual warning category of the message is a
218 subclass of the specified warning category.  The full class name must
219 be given.  The
220 .I module
221 field matches the (fully-qualified) module name; this match is
222 case-sensitive.  The
223 .I line
224 field matches the line number, where zero matches all line numbers and
225 is thus equivalent to an omitted line number.
227 .B \-x
228 Skip the first line of the source.  This is intended for a DOS
229 specific hack only.  Warning: the line numbers in error messages will
230 be off by one!
231 .SH INTERPRETER INTERFACE
232 The interpreter interface resembles that of the UNIX shell: when
233 called with standard input connected to a tty device, it prompts for
234 commands and executes them until an EOF is read; when called with a
235 file name argument or with a file as standard input, it reads and
236 executes a
237 .I script
238 from that file;
239 when called with
240 .B \-c
241 .I command,
242 it executes the Python statement(s) given as
243 .I command.
244 Here
245 .I command
246 may contain multiple statements separated by newlines.
247 Leading whitespace is significant in Python statements!
248 In non-interactive mode, the entire input is parsed before it is
249 executed.
251 If available, the script name and additional arguments thereafter are
252 passed to the script in the Python variable
253 .I sys.argv ,
254 which is a list of strings (you must first
255 .I import sys
256 to be able to access it).
257 If no script name is given,
258 .I sys.argv[0]
259 is an empty string; if
260 .B \-c
261 is used,
262 .I sys.argv[0]
263 contains the string
264 .I '-c'.
265 Note that options interpreted by the Python interpreter itself
266 are not placed in
267 .I sys.argv.
269 In interactive mode, the primary prompt is `>>>'; the second prompt
270 (which appears when a command is not complete) is `...'.
271 The prompts can be changed by assignment to
272 .I sys.ps1
274 .I sys.ps2.
275 The interpreter quits when it reads an EOF at a prompt.
276 When an unhandled exception occurs, a stack trace is printed and
277 control returns to the primary prompt; in non-interactive mode, the
278 interpreter exits after printing the stack trace.
279 The interrupt signal raises the
280 .I Keyboard\%Interrupt
281 exception; other UNIX signals are not caught (except that SIGPIPE is
282 sometimes ignored, in favor of the
283 .I IOError
284 exception).  Error messages are written to stderr.
285 .SH FILES AND DIRECTORIES
286 These are subject to difference depending on local installation
287 conventions; ${prefix} and ${exec_prefix} are installation-dependent
288 and should be interpreted as for GNU software; they may be the same.
289 The default for both is \fI/usr/local\fP.
290 .IP \fI${exec_prefix}/bin/python\fP
291 Recommended location of the interpreter.
293 .I ${prefix}/lib/python<version>
295 .I ${exec_prefix}/lib/python<version>
297 Recommended locations of the directories containing the standard
298 modules.
301 .I ${prefix}/include/python<version>
303 .I ${exec_prefix}/include/python<version>
305 Recommended locations of the directories containing the include files
306 needed for developing Python extensions and embedding the
307 interpreter.
309 .SH ENVIRONMENT VARIABLES
310 .IP PYTHONHOME
311 Change the location of the standard Python libraries.  By default, the
312 libraries are searched in ${prefix}/lib/python<version> and
313 ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
314 are installation-dependent directories, both defaulting to
315 \fI/usr/local\fP.  When $PYTHONHOME is set to a single directory, its value
316 replaces both ${prefix} and ${exec_prefix}.  To specify different values
317 for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
318 .IP PYTHONPATH
319 Augments the default search path for module files.
320 The format is the same as the shell's $PATH: one or more directory
321 pathnames separated by colons.
322 Non-existent directories are silently ignored.
323 The default search path is installation dependent, but generally
324 begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
325 The default search path is always appended to $PYTHONPATH.
326 If a script argument is given, the directory containing the script is
327 inserted in the path in front of $PYTHONPATH.
328 The search path can be manipulated from within a Python program as the
329 variable
330 .I sys.path .
331 .IP PYTHONSTARTUP
332 If this is the name of a readable file, the Python commands in that
333 file are executed before the first prompt is displayed in interactive
334 mode.
335 The file is executed in the same name space where interactive commands
336 are executed so that objects defined or imported in it can be used
337 without qualification in the interactive session.
338 You can also change the prompts
339 .I sys.ps1
341 .I sys.ps2
342 in this file.
343 .IP PYTHONY2K
344 Set this to a non-empty string to cause the \fItime\fP module to
345 require dates specified as strings to include 4-digit years, otherwise
346 2-digit years are converted based on rules described in the \fItime\fP
347 module documentation.
348 .IP PYTHONOPTIMIZE
349 If this is set to a non-empty string it is equivalent to specifying
350 the \fB\-O\fP option. If set to an integer, it is equivalent to
351 specifying \fB\-O\fP multiple times.
352 .IP PYTHONDEBUG
353 If this is set to a non-empty string it is equivalent to specifying
354 the \fB\-d\fP option. If set to an integer, it is equivalent to
355 specifying \fB\-d\fP multiple times.
356 .IP PYTHONINSPECT
357 If this is set to a non-empty string it is equivalent to specifying
358 the \fB\-i\fP option.
359 .IP PYTHONUNBUFFERED
360 If this is set to a non-empty string it is equivalent to specifying
361 the \fB\-u\fP option.
362 .IP PYTHONVERBOSE
363 If this is set to a non-empty string it is equivalent to specifying
364 the \fB\-v\fP option. If set to an integer, it is equivalent to
365 specifying \fB\-v\fP multiple times. 
366 .SH AUTHOR
367 The Python Software Foundation: http://www.python.org/psf
368 .SH INTERNET RESOURCES
369 Main website:  http://www.python.org/
371 Documentation:  http://docs.python.org/
373 Community website:  http://starship.python.net/
375 Developer resources:  http://www.python.org/dev/
377 FTP:  ftp://ftp.python.org/pub/python/
379 Module repository:  http://www.vex.net/parnassus/
381 Newsgroups:  comp.lang.python, comp.lang.python.announce
382 .SH LICENSING
383 Python is distributed under an Open Source license.  See the file
384 "LICENSE" in the Python source distribution for information on terms &
385 conditions for accessing and otherwise using Python and for a
386 DISCLAIMER OF ALL WARRANTIES.