move sections
[python/dscho.git] / Misc / python.man
blob261a118944ffbe2193338ca94ee2461c6a205526
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 \-B
14 .B \-d
17 .B \-E
20 .B \-h
23 .B \-i
26 .B \-m 
27 .I module-name
29 .br
30        [
31 .B \-O
34 .B \-O0
37 .B -Q
38 .I argument
41 .B \-s
44 .B \-S
47 .B \-t
50 .B \-u
52 .br
53        [
54 .B \-v
57 .B \-V
60 .B \-W
61 .I argument
64 .B \-x
67 .B \-3
70 .B \-?
72 .br
73        [
74 .B \-c
75 .I command
77 .I script
82 .I arguments
84 .SH DESCRIPTION
85 Python is an interpreted, interactive, object-oriented programming
86 language that combines remarkable power with very clear syntax.
87 For an introduction to programming in Python you are referred to the
88 Python Tutorial.
89 The Python Library Reference documents built-in and standard types,
90 constants, functions and modules.
91 Finally, the Python Reference Manual describes the syntax and
92 semantics of the core language in (perhaps too) much detail.
93 (These documents may be located via the
94 .B "INTERNET RESOURCES"
95 below; they may be installed on your system as well.)
96 .PP
97 Python's basic power can be extended with your own modules written in
98 C or C++.
99 On most systems such modules may be dynamically loaded.
100 Python is also adaptable as an extension language for existing
101 applications.
102 See the internal documentation for hints.
104 Documentation for installed Python modules and packages can be 
105 viewed by running the 
106 .B pydoc
107 program.  
108 .SH COMMAND LINE OPTIONS
110 .B \-B
111 Don't write
112 .I .py[co]
113 files on import. See also PYTHONDONTWRITEBYTECODE.
115 .BI "\-c " command
116 Specify the command to execute (see next section).
117 This terminates the option list (following options are passed as
118 arguments to the command).
120 .B \-d
121 Turn on parser debugging output (for wizards only, depending on
122 compilation options).
124 .B \-E
125 Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
126 the behavior of the interpreter.
128 .B \-h ", " \-? ", "\-\-help
129 Prints the usage for the interpreter executable and exits.
131 .B \-i
132 When a script is passed as first argument or the \fB\-c\fP option is
133 used, enter interactive mode after executing the script or the
134 command.  It does not read the $PYTHONSTARTUP file.  This can be
135 useful to inspect global variables or a stack trace when a script
136 raises an exception.
138 .BI "\-m " module-name
139 Searches 
140 .I sys.path 
141 for the named module and runs the corresponding 
142 .I .py 
143 file as a script.
145 .B \-O
146 Turn on basic optimizations.  This changes the filename extension for
147 compiled (bytecode) files from
148 .I .pyc
149 to \fI.pyo\fP.  Given twice, causes docstrings to be discarded.
151 .B \-O0
152 Discard docstrings in addition to the \fB-O\fP optimizations.
154 .BI "\-Q " argument
155 Division control; see PEP 238.  The argument must be one of "old" (the
156 default, int/int and long/long return an int or long), "new" (new
157 division semantics, i.e. int/int and long/long returns a float),
158 "warn" (old division semantics with a warning for int/int and
159 long/long), or "warnall" (old division semantics with a warning for
160 all use of the division operator).  For a use of "warnall", see the
161 Tools/scripts/fixdiv.py script.
163 .B \-s
164 Don't add user site directory to sys.path.
166 .B \-S
167 Disable the import of the module
168 .I site
169 and the site-dependent manipulations of
170 .I sys.path
171 that it entails.
173 .B \-t
174 Issue a warning when a source file mixes tabs and spaces for
175 indentation in a way that makes it depend on the worth of a tab
176 expressed in spaces.  Issue an error when the option is given twice.
178 .B \-u
179 Force stdin, stdout and stderr to be totally unbuffered.  On systems
180 where it matters, also put stdin, stdout and stderr in binary mode.
181 Note that there is internal buffering in xreadlines(), readlines() and
182 file-object iterators ("for line in sys.stdin") which is not
183 influenced by this option.  To work around this, you will want to use
184 "sys.stdin.readline()" inside a "while 1:" loop.
186 .B \-v
187 Print a message each time a module is initialized, showing the place
188 (filename or built-in module) from which it is loaded.  When given
189 twice, print a message for each file that is checked for when 
190 searching for a module.  Also provides information on module cleanup
191 at exit.
193 .B \-V ", " \-\-version
194 Prints the Python version number of the executable and exits.
196 .BI "\-W " argument
197 Warning control.  Python sometimes prints warning message to
198 .IR sys.stderr .
199 A typical warning message has the following form:
200 .IB file ":" line ": " category ": " message.
201 By default, each warning is printed once for each source line where it
202 occurs.  This option controls how often warnings are printed.
203 Multiple
204 .B \-W
205 options may be given; when a warning matches more than one
206 option, the action for the last matching option is performed.
207 Invalid
208 .B \-W
209 options are ignored (a warning message is printed about invalid
210 options when the first warning is issued).  Warnings can also be
211 controlled from within a Python program using the
212 .I warnings
213 module.
215 The simplest form of
216 .I argument
217 is one of the following
218 .I action
219 strings (or a unique abbreviation):
220 .B ignore
221 to ignore all warnings;
222 .B default
223 to explicitly request the default behavior (printing each warning once
224 per source line);
225 .B all
226 to print a warning each time it occurs (this may generate many
227 messages if a warning is triggered repeatedly for the same source
228 line, such as inside a loop);
229 .B module
230 to print each warning only the first time it occurs in each
231 module;
232 .B once
233 to print each warning only the first time it occurs in the program; or
234 .B error
235 to raise an exception instead of printing a warning message.
237 The full form of
238 .I argument
240 .IB action : message : category : module : line.
241 Here,
242 .I action
243 is as explained above but only applies to messages that match the
244 remaining fields.  Empty fields match all values; trailing empty
245 fields may be omitted.  The
246 .I message
247 field matches the start of the warning message printed; this match is
248 case-insensitive.  The
249 .I category
250 field matches the warning category.  This must be a class name; the
251 match test whether the actual warning category of the message is a
252 subclass of the specified warning category.  The full class name must
253 be given.  The
254 .I module
255 field matches the (fully-qualified) module name; this match is
256 case-sensitive.  The
257 .I line
258 field matches the line number, where zero matches all line numbers and
259 is thus equivalent to an omitted line number.
261 .B \-x
262 Skip the first line of the source.  This is intended for a DOS
263 specific hack only.  Warning: the line numbers in error messages will
264 be off by one!
266 .B \-3
267 Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
268 .SH INTERPRETER INTERFACE
269 The interpreter interface resembles that of the UNIX shell: when
270 called with standard input connected to a tty device, it prompts for
271 commands and executes them until an EOF is read; when called with a
272 file name argument or with a file as standard input, it reads and
273 executes a
274 .I script
275 from that file;
276 when called with
277 .B \-c
278 .I command,
279 it executes the Python statement(s) given as
280 .I command.
281 Here
282 .I command
283 may contain multiple statements separated by newlines.
284 Leading whitespace is significant in Python statements!
285 In non-interactive mode, the entire input is parsed before it is
286 executed.
288 If available, the script name and additional arguments thereafter are
289 passed to the script in the Python variable
290 .I sys.argv ,
291 which is a list of strings (you must first
292 .I import sys
293 to be able to access it).
294 If no script name is given,
295 .I sys.argv[0]
296 is an empty string; if
297 .B \-c
298 is used,
299 .I sys.argv[0]
300 contains the string
301 .I '-c'.
302 Note that options interpreted by the Python interpreter itself
303 are not placed in
304 .I sys.argv.
306 In interactive mode, the primary prompt is `>>>'; the second prompt
307 (which appears when a command is not complete) is `...'.
308 The prompts can be changed by assignment to
309 .I sys.ps1
311 .I sys.ps2.
312 The interpreter quits when it reads an EOF at a prompt.
313 When an unhandled exception occurs, a stack trace is printed and
314 control returns to the primary prompt; in non-interactive mode, the
315 interpreter exits after printing the stack trace.
316 The interrupt signal raises the
317 .I Keyboard\%Interrupt
318 exception; other UNIX signals are not caught (except that SIGPIPE is
319 sometimes ignored, in favor of the
320 .I IOError
321 exception).  Error messages are written to stderr.
322 .SH FILES AND DIRECTORIES
323 These are subject to difference depending on local installation
324 conventions; ${prefix} and ${exec_prefix} are installation-dependent
325 and should be interpreted as for GNU software; they may be the same.
326 The default for both is \fI/usr/local\fP.
327 .IP \fI${exec_prefix}/bin/python\fP
328 Recommended location of the interpreter.
330 .I ${prefix}/lib/python<version>
332 .I ${exec_prefix}/lib/python<version>
334 Recommended locations of the directories containing the standard
335 modules.
338 .I ${prefix}/include/python<version>
340 .I ${exec_prefix}/include/python<version>
342 Recommended locations of the directories containing the include files
343 needed for developing Python extensions and embedding the
344 interpreter.
346 .IP \fI~/.pythonrc.py\fP
347 User-specific initialization file loaded by the \fIuser\fP module;
348 not used by default or by most applications.
349 .SH ENVIRONMENT VARIABLES
350 .IP PYTHONHOME
351 Change the location of the standard Python libraries.  By default, the
352 libraries are searched in ${prefix}/lib/python<version> and
353 ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
354 are installation-dependent directories, both defaulting to
355 \fI/usr/local\fP.  When $PYTHONHOME is set to a single directory, its value
356 replaces both ${prefix} and ${exec_prefix}.  To specify different values
357 for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
358 .IP PYTHONPATH
359 Augments the default search path for module files.
360 The format is the same as the shell's $PATH: one or more directory
361 pathnames separated by colons.
362 Non-existent directories are silently ignored.
363 The default search path is installation dependent, but generally
364 begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
365 The default search path is always appended to $PYTHONPATH.
366 If a script argument is given, the directory containing the script is
367 inserted in the path in front of $PYTHONPATH.
368 The search path can be manipulated from within a Python program as the
369 variable
370 .I sys.path .
371 .IP PYTHONSTARTUP
372 If this is the name of a readable file, the Python commands in that
373 file are executed before the first prompt is displayed in interactive
374 mode.
375 The file is executed in the same name space where interactive commands
376 are executed so that objects defined or imported in it can be used
377 without qualification in the interactive session.
378 You can also change the prompts
379 .I sys.ps1
381 .I sys.ps2
382 in this file.
383 .IP PYTHONY2K
384 Set this to a non-empty string to cause the \fItime\fP module to
385 require dates specified as strings to include 4-digit years, otherwise
386 2-digit years are converted based on rules described in the \fItime\fP
387 module documentation.
388 .IP PYTHONOPTIMIZE
389 If this is set to a non-empty string it is equivalent to specifying
390 the \fB\-O\fP option. If set to an integer, it is equivalent to
391 specifying \fB\-O\fP multiple times.
392 .IP PYTHONDEBUG
393 If this is set to a non-empty string it is equivalent to specifying
394 the \fB\-d\fP option. If set to an integer, it is equivalent to
395 specifying \fB\-d\fP multiple times.
396 .IP PYTHONDONTWRITEBYTECODE
397 If this is set to a non-empty string it is equivalent to specifying
398 the \fB\-B\fP option (don't try to write
399 .I .py[co]
400 files).
401 .IP PYTHONINSPECT
402 If this is set to a non-empty string it is equivalent to specifying
403 the \fB\-i\fP option.
404 .IP PYTHONNOUSERSITE
405 If this is set to a non-empty string it is equivalent to specifying
406 the \fB\-s\fP option (Don't add the user site directory to sys.path).
407 .IP PYTHONUNBUFFERED
408 If this is set to a non-empty string it is equivalent to specifying
409 the \fB\-u\fP option.
410 .IP PYTHONVERBOSE
411 If this is set to a non-empty string it is equivalent to specifying
412 the \fB\-v\fP option. If set to an integer, it is equivalent to
413 specifying \fB\-v\fP multiple times. 
414 .IP PYTHONWARNINGS
415 If this is set to a comma-separated string it is equivalent to
416 specifying the \fB\-W\fP option for each separate value.
417 .SH AUTHOR
418 The Python Software Foundation: http://www.python.org/psf
419 .SH INTERNET RESOURCES
420 Main website:  http://www.python.org/
422 Documentation:  http://docs.python.org/
424 Developer resources:  http://www.python.org/dev/
426 Downloads:  http://python.org/download/
428 Module repository:  http://pypi.python.org/
430 Newsgroups:  comp.lang.python, comp.lang.python.announce
431 .SH LICENSING
432 Python is distributed under an Open Source license.  See the file
433 "LICENSE" in the Python source distribution for information on terms &
434 conditions for accessing and otherwise using Python and for a
435 DISCLAIMER OF ALL WARRANTIES.