Commit e47da0ae authored by Guido van Rossum's avatar Guido van Rossum

AMK's megapatch:

	* \bcode, \ecode added everywhere
	* \label{module-foo} added everywhere
	* A few \seealso sections added.
	* Indentation fixed inside verbatim in lib*tex files
parent 3c2a056f
This diff is collapsed.
This diff is collapsed.
\section{Standard Module \sectcode{aifc}} \section{Standard Module \sectcode{aifc}}
\label{module-aifc}
\stmodindex{aifc} \stmodindex{aifc}
This module provides support for reading and writing AIFF and AIFF-C This module provides support for reading and writing AIFF and AIFF-C
......
\section{Built-in Module \sectcode{al}} \section{Built-in Module \sectcode{al}}
\label{module-al}
\bimodindex{al} \bimodindex{al}
This module provides access to the audio facilities of the SGI Indy This module provides access to the audio facilities of the SGI Indy
......
...@@ -82,7 +82,7 @@ For example: ...@@ -82,7 +82,7 @@ For example:
aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
The following methods are defined for capability objects. The following methods are defined for capability objects.
\renewcommand{\indexsubitem}{(capability method)} \renewcommand{\indexsubitem}{(capability method)}
......
\section{Built-in Module \sectcode{array}} \section{Built-in Module \sectcode{array}}
\label{module-array}
\bimodindex{array} \bimodindex{array}
\index{arrays} \index{arrays}
......
\section{Built-in Module \sectcode{audioop}} \section{Built-in Module \sectcode{audioop}}
\label{module-audioop}
\bimodindex{audioop} \bimodindex{audioop}
The \code{audioop} module contains some useful operations on sound fragments. The \code{audioop} module contains some useful operations on sound fragments.
...@@ -210,7 +211,7 @@ def mul_stereo(sample, width, lfactor, rfactor): ...@@ -210,7 +211,7 @@ def mul_stereo(sample, width, lfactor, rfactor):
rsample = audioop.tostereo(rsample, width, 0, 1) rsample = audioop.tostereo(rsample, width, 0, 1)
return audioop.add(lsample, rsample, width) return audioop.add(lsample, rsample, width)
\end{verbatim}\ecode \end{verbatim}\ecode
%
If you use the ADPCM coder to build network packets and you want your If you use the ADPCM coder to build network packets and you want your
protocol to be stateless (i.e.\ to be able to tolerate packet loss) protocol to be stateless (i.e.\ to be able to tolerate packet loss)
you should not only transmit the data but also the state. Note that you should not only transmit the data but also the state. Note that
......
\section{Standard Module \sectcode{base64}} \section{Standard Module \sectcode{base64}}
\label{module-base64}
\stmodindex{base64} \stmodindex{base64}
This module perform base-64 encoding and decoding of arbitrary binary This module perform base-64 encoding and decoding of arbitrary binary
......
\section{Standard Module \sectcode{Bastion}} \section{Standard Module \sectcode{Bastion}}
\label{module-Bastion}
\stmodindex{Bastion} \stmodindex{Bastion}
\renewcommand{\indexsubitem}{(in module Bastion)} \renewcommand{\indexsubitem}{(in module Bastion)}
......
\section{Standard module \sectcode{binhex}} \section{Standard module \sectcode{binhex}}
\label{module-binhex}
\stmodindex{binhex} \stmodindex{binhex}
This module encodes and decodes files in binhex4 format, a format This module encodes and decodes files in binhex4 format, a format
......
\section{Built-in Module \sectcode{__builtin__}} \section{Built-in Module \sectcode{__builtin__}}
\label{module-builtin}
\bimodindex{__builtin__} \bimodindex{__builtin__}
This module provides direct access to all `built-in' identifiers of This module provides direct access to all `built-in' identifiers of
......
\section{Built-in Module \sectcode{cd}} \section{Built-in Module \sectcode{cd}}
\label{module-cd}
\bimodindex{cd} \bimodindex{cd}
This module provides an interface to the Silicon Graphics CD library. This module provides an interface to the Silicon Graphics CD library.
......
\section{Standard Module \sectcode{cgi}} \section{Standard Module \sectcode{cgi}}
\label{module-cgi}
\stmodindex{cgi} \stmodindex{cgi}
\indexii{WWW}{server} \indexii{WWW}{server}
\indexii{CGI}{protocol} \indexii{CGI}{protocol}
...@@ -39,21 +40,21 @@ by a blank line. The first section contains a number of headers, ...@@ -39,21 +40,21 @@ by a blank line. The first section contains a number of headers,
telling the client what kind of data is following. Python code to telling the client what kind of data is following. Python code to
generate a minimal header section looks like this: generate a minimal header section looks like this:
\begin{verbatim} \bcode\begin{verbatim}
print "Content-type: text/html" # HTML is following print "Content-type: text/html" # HTML is following
print # blank line, end of headers print # blank line, end of headers
\end{verbatim} \end{verbatim}\ecode
%
The second section is usually HTML, which allows the client software The second section is usually HTML, which allows the client software
to display nicely formatted text with header, in-line images, etc. to display nicely formatted text with header, in-line images, etc.
Here's Python code that prints a simple piece of HTML: Here's Python code that prints a simple piece of HTML:
\begin{verbatim} \bcode\begin{verbatim}
print "<TITLE>CGI script output</TITLE>" print "<TITLE>CGI script output</TITLE>"
print "<H1>This is my first CGI script</H1>" print "<H1>This is my first CGI script</H1>"
print "Hello, world!" print "Hello, world!"
\end{verbatim} \end{verbatim}\ecode
%
(It may not be fully legal HTML according to the letter of the (It may not be fully legal HTML according to the letter of the
standard, but any browser will understand it.) standard, but any browser will understand it.)
...@@ -76,19 +77,19 @@ dictionary. For instance, the following code (which assumes that the ...@@ -76,19 +77,19 @@ dictionary. For instance, the following code (which assumes that the
\code{Content-type} header and blank line have already been printed) checks that \code{Content-type} header and blank line have already been printed) checks that
the fields \code{name} and \code{addr} are both set to a non-empty string: the fields \code{name} and \code{addr} are both set to a non-empty string:
\begin{verbatim} \bcode\begin{verbatim}
form = cgi.FieldStorage() form = cgi.FieldStorage()
form_ok = 0 form_ok = 0
if form.has_key("name") and form.has_key("addr"): if form.has_key("name") and form.has_key("addr"):
if form["name"].value != "" and form["addr"].value != "": if form["name"].value != "" and form["addr"].value != "":
form_ok = 1 form_ok = 1
if not form_ok: if not form_ok:
print "<H1>Error</H1>" print "<H1>Error</H1>"
print "Please fill in the name and addr fields." print "Please fill in the name and addr fields."
return return
...further form processing here... ...further form processing here...
\end{verbatim} \end{verbatim}\ecode
%
Here the fields, accessed through \code{form[key]}, are themselves instances Here the fields, accessed through \code{form[key]}, are themselves instances
of \code{FieldStorage} (or \code{MiniFieldStorage}, depending on the form encoding). of \code{FieldStorage} (or \code{MiniFieldStorage}, depending on the form encoding).
...@@ -100,9 +101,9 @@ name), use the \code{type()} function to determine whether you have a single ...@@ -100,9 +101,9 @@ name), use the \code{type()} function to determine whether you have a single
instance or a list of instances. For example, here's code that instance or a list of instances. For example, here's code that
concatenates any number of username fields, separated by commas: concatenates any number of username fields, separated by commas:
\begin{verbatim} \bcode\begin{verbatim}
username = form["username"] username = form["username"]
if type(username) is type([]): if type(username) is type([]):
# Multiple username fields specified # Multiple username fields specified
usernames = "" usernames = ""
for item in username: for item in username:
...@@ -112,28 +113,28 @@ concatenates any number of username fields, separated by commas: ...@@ -112,28 +113,28 @@ concatenates any number of username fields, separated by commas:
else: else:
# First item -- don't insert comma # First item -- don't insert comma
usernames = item.value usernames = item.value
else: else:
# Single username field specified # Single username field specified
usernames = username.value usernames = username.value
\end{verbatim} \end{verbatim}\ecode
%
If a field represents an uploaded file, the value attribute reads the If a field represents an uploaded file, the value attribute reads the
entire file in memory as a string. This may not be what you want. You can entire file in memory as a string. This may not be what you want. You can
test for an uploaded file by testing either the filename attribute or the test for an uploaded file by testing either the filename attribute or the
file attribute. You can then read the data at leasure from the file file attribute. You can then read the data at leasure from the file
attribute: attribute:
\begin{verbatim} \bcode\begin{verbatim}
fileitem = form["userfile"] fileitem = form["userfile"]
if fileitem.file: if fileitem.file:
# It's an uploaded file; count lines # It's an uploaded file; count lines
linecount = 0 linecount = 0
while 1: while 1:
line = fileitem.file.readline() line = fileitem.file.readline()
if not line: break if not line: break
linecount = linecount + 1 linecount = linecount + 1
\end{verbatim} \end{verbatim}\ecode
%
The file upload draft standard entertains the possibility of uploading The file upload draft standard entertains the possibility of uploading
multiple files from one field (using a recursive \code{multipart/*} multiple files from one field (using a recursive \code{multipart/*}
encoding). When this occurs, the item will be a dictionary-like encoding). When this occurs, the item will be a dictionary-like
...@@ -251,10 +252,10 @@ Unix file mode should be 755 (use \code{chmod 755 filename}). Make sure ...@@ -251,10 +252,10 @@ Unix file mode should be 755 (use \code{chmod 755 filename}). Make sure
that the first line of the script contains \code{\#!} starting in column 1 that the first line of the script contains \code{\#!} starting in column 1
followed by the pathname of the Python interpreter, for instance: followed by the pathname of the Python interpreter, for instance:
\begin{verbatim} \bcode\begin{verbatim}
#!/usr/local/bin/python #!/usr/local/bin/python
\end{verbatim} \end{verbatim}\ecode
%
Make sure the Python interpreter exists and is executable by ``others''. Make sure the Python interpreter exists and is executable by ``others''.
Make sure that any files your script needs to read or write are Make sure that any files your script needs to read or write are
...@@ -273,12 +274,12 @@ If you need to load modules from a directory which is not on Python's ...@@ -273,12 +274,12 @@ If you need to load modules from a directory which is not on Python's
default module search path, you can change the path in your script, default module search path, you can change the path in your script,
before importing other modules, e.g.: before importing other modules, e.g.:
\begin{verbatim} \bcode\begin{verbatim}
import sys import sys
sys.path.insert(0, "/usr/home/joe/lib/python") sys.path.insert(0, "/usr/home/joe/lib/python")
sys.path.insert(0, "/usr/local/lib/python") sys.path.insert(0, "/usr/local/lib/python")
\end{verbatim} \end{verbatim}\ecode
%
(This way, the directory inserted last will be searched first!) (This way, the directory inserted last will be searched first!)
Instructions for non-Unix systems will vary; check your HTTP server's Instructions for non-Unix systems will vary; check your HTTP server's
...@@ -311,10 +312,10 @@ Give it the right mode etc, and send it a request. If it's installed ...@@ -311,10 +312,10 @@ Give it the right mode etc, and send it a request. If it's installed
in the standard \code{cgi-bin} directory, it should be possible to send it a in the standard \code{cgi-bin} directory, it should be possible to send it a
request by entering a URL into your browser of the form: request by entering a URL into your browser of the form:
\begin{verbatim} \bcode\begin{verbatim}
http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home http://yourhostname/cgi-bin/cgi.py?name=Joe+Blow&addr=At+Home
\end{verbatim} \end{verbatim}\ecode
%
If this gives an error of type 404, the server cannot find the script If this gives an error of type 404, the server cannot find the script
-- perhaps you need to install it in a different directory. If it -- perhaps you need to install it in a different directory. If it
gives another error (e.g. 500), there's an installation problem that gives another error (e.g. 500), there's an installation problem that
...@@ -328,10 +329,10 @@ script, you should now be able to debug it. ...@@ -328,10 +329,10 @@ script, you should now be able to debug it.
The next step could be to call the \code{cgi} module's test() function from The next step could be to call the \code{cgi} module's test() function from
your script: replace its main code with the single statement your script: replace its main code with the single statement
\begin{verbatim} \bcode\begin{verbatim}
cgi.test() cgi.test()
\end{verbatim} \end{verbatim}\ecode
%
This should produce the same results as those gotten from installing This should produce the same results as those gotten from installing
the \code{cgi.py} file itself. the \code{cgi.py} file itself.
...@@ -363,19 +364,19 @@ Here are the rules: ...@@ -363,19 +364,19 @@ Here are the rules:
For example: For example:
\begin{verbatim} \bcode\begin{verbatim}
import sys import sys
import traceback import traceback
print "Content-type: text/html" print "Content-type: text/html"
print print
sys.stderr = sys.stdout sys.stderr = sys.stdout
try: try:
...your code here... ...your code here...
except: except:
print "\n\n<PRE>" print "\n\n<PRE>"
traceback.print_exc() traceback.print_exc()
\end{verbatim} \end{verbatim}\ecode
%
Notes: The assignment to \code{sys.stderr} is needed because the traceback Notes: The assignment to \code{sys.stderr} is needed because the traceback
prints to \code{sys.stderr}. The \code{print "$\backslash$n$\backslash$n<PRE>"} statement is necessary to prints to \code{sys.stderr}. The \code{print "$\backslash$n$\backslash$n<PRE>"} statement is necessary to
disable the word wrapping in HTML. disable the word wrapping in HTML.
...@@ -384,14 +385,14 @@ If you suspect that there may be a problem in importing the traceback ...@@ -384,14 +385,14 @@ If you suspect that there may be a problem in importing the traceback
module, you can use an even more robust approach (which only uses module, you can use an even more robust approach (which only uses
built-in modules): built-in modules):
\begin{verbatim} \bcode\begin{verbatim}
import sys import sys
sys.stderr = sys.stdout sys.stderr = sys.stdout
print "Content-type: text/plain" print "Content-type: text/plain"
print print
...your code here... ...your code here...
\end{verbatim} \end{verbatim}\ecode
%
This relies on the Python interpreter to print the traceback. The This relies on the Python interpreter to print the traceback. The
content type of the output is set to plain text, which disables all content type of the output is set to plain text, which disables all
HTML processing. If your script works, the raw HTML will be displayed HTML processing. If your script works, the raw HTML will be displayed
......
\section{Standard Module \sectcode{copy}} \section{Standard Module \sectcode{copy}}
\label{module-copy}
\stmodindex{copy} \stmodindex{copy}
\renewcommand{\indexsubitem}{(copy function)} \renewcommand{\indexsubitem}{(copy function)}
\ttindex{copy} \ttindex{copy}
...@@ -8,13 +9,13 @@ This module provides generic (shallow and deep) copying operations. ...@@ -8,13 +9,13 @@ This module provides generic (shallow and deep) copying operations.
Interface summary: Interface summary:
\begin{verbatim} \bcode\begin{verbatim}
import copy import copy
x = copy.copy(y) # make a shallow copy of y x = copy.copy(y) # make a shallow copy of y
x = copy.deepcopy(y) # make a deep copy of y x = copy.deepcopy(y) # make a deep copy of y
\end{verbatim} \end{verbatim}\ecode
%
For module specific errors, \code{copy.error} is raised. For module specific errors, \code{copy.error} is raised.
The difference between shallow and deep copying is only relevant for The difference between shallow and deep copying is only relevant for
......
\section{Built-in module {\tt crypt}} \section{Built-in Module {\tt crypt}}
\label{module-crypt}
\bimodindex{crypt} \bimodindex{crypt}
This module implements an interface to the crypt({\bf 3}) routine, This module implements an interface to the crypt({\bf 3}) routine,
......
\section{Built-in Module \sectcode{dbm}} \section{Built-in Module \sectcode{dbm}}
\label{module-dbm}
\bimodindex{dbm} \bimodindex{dbm}
The \code{dbm} module provides an interface to the \UNIX{} The \code{dbm} module provides an interface to the \UNIX{}
......
...@@ -65,7 +65,7 @@ rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1) ...@@ -65,7 +65,7 @@ rv = fcntl(file.fileno(), FCNTL.O_NDELAY, 1)
lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0) lockdata = struct.pack('hhllhh', FCNTL.F_WRLCK, 0, 0, 0, 0, 0)
rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata) rv = fcntl(file.fileno(), FCNTL.F_SETLKW, lockdata)
\end{verbatim}\ecode \end{verbatim}\ecode
%
Note that in the first example the return value variable \code{rv} will Note that in the first example the return value variable \code{rv} will
hold an integer value; in the second example it will hold a string hold an integer value; in the second example it will hold a string
value. The structure lay-out for the \var{lockadata} variable is value. The structure lay-out for the \var{lockadata} variable is
......
\section{Built-in Module \sectcode{fl}} \section{Built-in Module \sectcode{fl}}
\label{module-fl}
\bimodindex{fl} \bimodindex{fl}
This module provides an interface to the FORMS Library by Mark This module provides an interface to the FORMS Library by Mark
...@@ -471,7 +472,7 @@ the defined names. Suggested use: ...@@ -471,7 +472,7 @@ the defined names. Suggested use:
import fl import fl
from FL import * from FL import *
\end{verbatim}\ecode \end{verbatim}\ecode
%
\section{Standard Module \sectcode{flp}} \section{Standard Module \sectcode{flp}}
\stmodindex{flp} \stmodindex{flp}
......
\section{Built-in Module \sectcode{fm}} \section{Built-in Module \sectcode{fm}}
\label{module-fm}
\bimodindex{fm} \bimodindex{fm}
This module provides access to the IRIS {\em Font Manager} library. This module provides access to the IRIS {\em Font Manager} library.
......
\section{Standard Module \sectcode{fnmatch}} \section{Standard Module \sectcode{fnmatch}}
\label{module-fnmatch}
\stmodindex{fnmatch} \stmodindex{fnmatch}
This module provides support for Unix shell-style wildcards, which are This module provides support for Unix shell-style wildcards, which are
......
\section{Standard Module \sectcode{formatter}} \section{Standard Module \sectcode{formatter}}
\label{module-formatter}
\stmodindex{formatter} \stmodindex{formatter}
\renewcommand{\indexsubitem}{(in module formatter)} \renewcommand{\indexsubitem}{(in module formatter)}
......
\section{Standard Module \sectcode{ftplib}} \section{Standard Module \sectcode{ftplib}}
\label{module-ftplib}
\stmodindex{ftplib} \stmodindex{ftplib}
\renewcommand{\indexsubitem}{(in module ftplib)} \renewcommand{\indexsubitem}{(in module ftplib)}
...@@ -13,7 +14,7 @@ more information on FTP (File Transfer Protocol), see Internet RFC ...@@ -13,7 +14,7 @@ more information on FTP (File Transfer Protocol), see Internet RFC
Here's a sample session using the \code{ftplib} module: Here's a sample session using the \code{ftplib} module:
\begin{verbatim} \bcode\begin{verbatim}
>>> from ftplib import FTP >>> from ftplib import FTP
>>> ftp = FTP('ftp.cwi.nl') # connect to host, default port >>> ftp = FTP('ftp.cwi.nl') # connect to host, default port
>>> ftp.login() # user anonymous, passwd user@hostname >>> ftp.login() # user anonymous, passwd user@hostname
...@@ -26,8 +27,8 @@ dr-xr-srwt 105 ftp-usr pdmaint 1536 Mar 21 14:32 .. ...@@ -26,8 +27,8 @@ dr-xr-srwt 105 ftp-usr pdmaint 1536 Mar 21 14:32 ..
. .
. .
>>> ftp.quit() >>> ftp.quit()
\end{verbatim} \end{verbatim}\ecode
%
The module defines the following items: The module defines the following items:
\begin{funcdesc}{FTP}{\optional{host\optional{\, user\, passwd\, acct}}} \begin{funcdesc}{FTP}{\optional{host\optional{\, user\, passwd\, acct}}}
......
...@@ -119,7 +119,7 @@ be added to the end of the the argument list. ...@@ -119,7 +119,7 @@ be added to the end of the the argument list.
2 2
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
This function can also be used to execute arbitrary code objects This function can also be used to execute arbitrary code objects
(e.g.\ created by \code{compile()}). In this case pass a code (e.g.\ created by \code{compile()}). In this case pass a code
object instead of a string. The code object must have been compiled object instead of a string. The code object must have been compiled
......
\section{Standard Module \sectcode{getopt}} \section{Standard Module \sectcode{getopt}}
\label{module-getopt}
\stmodindex{getopt} \stmodindex{getopt}
This module helps scripts to parse the command line arguments in This module helps scripts to parse the command line arguments in
...@@ -56,7 +57,7 @@ An example using only \UNIX{} style options: ...@@ -56,7 +57,7 @@ An example using only \UNIX{} style options:
['a1', 'a2'] ['a1', 'a2']
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
Using long option names is equally easy: Using long option names is equally easy:
\bcode\begin{verbatim} \bcode\begin{verbatim}
...@@ -72,7 +73,7 @@ Using long option names is equally easy: ...@@ -72,7 +73,7 @@ Using long option names is equally easy:
['a1', 'a2'] ['a1', 'a2']
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
The exception The exception
\code{getopt.error = 'getopt.error'} \code{getopt.error = 'getopt.error'}
is raised when an unrecognized option is found in the argument list or is raised when an unrecognized option is found in the argument list or
......
\section{Built-in Module \sectcode{gl}} \section{Built-in Module \sectcode{gl}}
\label{module-gl}
\bimodindex{gl} \bimodindex{gl}
This module provides access to the Silicon Graphics This module provides access to the Silicon Graphics
...@@ -43,13 +44,13 @@ For example, the C call ...@@ -43,13 +44,13 @@ For example, the C call
\bcode\begin{verbatim} \bcode\begin{verbatim}
lmdef(deftype, index, np, props) lmdef(deftype, index, np, props)
\end{verbatim}\ecode \end{verbatim}\ecode
%
is translated to Python as is translated to Python as
\bcode\begin{verbatim} \bcode\begin{verbatim}
lmdef(deftype, index, props) lmdef(deftype, index, props)
\end{verbatim}\ecode \end{verbatim}\ecode
%
\item \item
Output arguments are omitted from the argument list; they are Output arguments are omitted from the argument list; they are
transmitted as function return values instead. transmitted as function return values instead.
...@@ -62,13 +63,13 @@ Examples: the C call ...@@ -62,13 +63,13 @@ Examples: the C call
\bcode\begin{verbatim} \bcode\begin{verbatim}
getmcolor(i, &red, &green, &blue) getmcolor(i, &red, &green, &blue)
\end{verbatim}\ecode \end{verbatim}\ecode
%
is translated to Python as is translated to Python as
\bcode\begin{verbatim} \bcode\begin{verbatim}
red, green, blue = getmcolor(i) red, green, blue = getmcolor(i)
\end{verbatim}\ecode \end{verbatim}\ecode
%
\end{itemize} \end{itemize}
The following functions are non-standard or have special argument The following functions are non-standard or have special argument
...@@ -183,7 +184,7 @@ def main(): ...@@ -183,7 +184,7 @@ def main():
main() main()
\end{verbatim}\ecode \end{verbatim}\ecode
%
\section{Standard Modules \sectcode{GL} and \sectcode{DEVICE}} \section{Standard Modules \sectcode{GL} and \sectcode{DEVICE}}
\nodename{GL and DEVICE} \nodename{GL and DEVICE}
\stmodindex{GL} \stmodindex{GL}
......
\section{Standard Module \sectcode{glob}} \section{Standard Module \sectcode{glob}}
\label{module-glob}
\stmodindex{glob} \stmodindex{glob}
\renewcommand{\indexsubitem}{(in module glob)} \renewcommand{\indexsubitem}{(in module glob)}
...@@ -24,7 +25,7 @@ For example, consider a directory containing only the following files: ...@@ -24,7 +25,7 @@ For example, consider a directory containing only the following files:
will produce the following results. Notice how any leading components will produce the following results. Notice how any leading components
of the path are preserved. of the path are preserved.
\begin{verbatim} \bcode\begin{verbatim}
>>> import glob >>> import glob
>>> glob.glob('./[0-9].*') >>> glob.glob('./[0-9].*')
['./1.gif', './2.txt'] ['./1.gif', './2.txt']
...@@ -32,4 +33,4 @@ of the path are preserved. ...@@ -32,4 +33,4 @@ of the path are preserved.
['1.gif', 'card.gif'] ['1.gif', 'card.gif']
>>> glob.glob('?.gif') >>> glob.glob('?.gif')
['1.gif'] ['1.gif']
\end{verbatim} \end{verbatim}\ecode
\section{Standard Module \sectcode{gopherlib}} \section{Standard Module \sectcode{gopherlib}}
\label{module-gopherlib}
\stmodindex{gopherlib} \stmodindex{gopherlib}
\renewcommand{\indexsubitem}{(in module gopherlib)} \renewcommand{\indexsubitem}{(in module gopherlib)}
......
\section{Built-in Module \sectcode{grp}} \section{Built-in Module \sectcode{grp}}
\label{module-grp}
\bimodindex{grp} \bimodindex{grp}
This module provides access to the \UNIX{} group database. This module provides access to the \UNIX{} group database.
......
\section{Standard Module \sectcode{htmllib}} \section{Standard Module \sectcode{htmllib}}
\label{module-htmllib}
\stmodindex{htmllib} \stmodindex{htmllib}
\index{HTML} \index{HTML}
\index{hypertext} \index{hypertext}
...@@ -38,11 +39,11 @@ incomplete elements are saved in a buffer. To force processing of all ...@@ -38,11 +39,11 @@ incomplete elements are saved in a buffer. To force processing of all
unprocessed data, call the \code{close()} method. unprocessed data, call the \code{close()} method.
For example, to parse the entire contents of a file, use: For example, to parse the entire contents of a file, use:
\begin{verbatim} \bcode\begin{verbatim}
parser.feed(open('myfile.html').read()) parser.feed(open('myfile.html').read())
parser.close() parser.close()
\end{verbatim} \end{verbatim}\ecode
%
\item \item
The interface to define semantics for HTML tags is very simple: derive The interface to define semantics for HTML tags is very simple: derive
a class and define methods called \code{start_\var{tag}()}, a class and define methods called \code{start_\var{tag}()},
......
\section{Standard Module \sectcode{httplib}} \section{Standard Module \sectcode{httplib}}
\label{module-httplib}
\stmodindex{httplib} \stmodindex{httplib}
\index{HTTP} \index{HTTP}
...@@ -19,12 +20,12 @@ method should be used to connect to a server. For example, the ...@@ -19,12 +20,12 @@ method should be used to connect to a server. For example, the
following calls all create instances that connect to the server at the following calls all create instances that connect to the server at the
same host and port: same host and port:
\begin{verbatim} \bcode\begin{verbatim}
>>> h1 = httplib.HTTP('www.cwi.nl') >>> h1 = httplib.HTTP('www.cwi.nl')
>>> h2 = httplib.HTTP('www.cwi.nl:80') >>> h2 = httplib.HTTP('www.cwi.nl:80')
>>> h3 = httplib.HTTP('www.cwi.nl', 80) >>> h3 = httplib.HTTP('www.cwi.nl', 80)
\end{verbatim} \end{verbatim}\ecode
%
Once an \code{HTTP} instance has been connected to an HTTP server, it Once an \code{HTTP} instance has been connected to an HTTP server, it
should be used as follows: should be used as follows:
...@@ -111,7 +112,7 @@ methods. ...@@ -111,7 +112,7 @@ methods.
Here is an example session: Here is an example session:
\begin{verbatim} \bcode\begin{verbatim}
>>> import httplib >>> import httplib
>>> h = httplib.HTTP('www.cwi.nl') >>> h = httplib.HTTP('www.cwi.nl')
>>> h.putrequest('GET', '/index.html') >>> h.putrequest('GET', '/index.html')
...@@ -124,4 +125,4 @@ Here is an example session: ...@@ -124,4 +125,4 @@ Here is an example session:
>>> data f.read() # Get the raw HTML >>> data f.read() # Get the raw HTML
>>> f.close() >>> f.close()
>>> >>>
\end{verbatim} \end{verbatim}\ecode
\section{Built-in Module \sectcode{imageop}} \section{Built-in Module \sectcode{imageop}}
\label{module-imageop}
\bimodindex{imageop} \bimodindex{imageop}
The \code{imageop} module contains some useful operations on images. The \code{imageop} module contains some useful operations on images.
......
\section{Built-in Module \sectcode{imgfile}} \section{Built-in Module \sectcode{imgfile}}
\label{module-imgfile}
\bimodindex{imgfile} \bimodindex{imgfile}
The imgfile module allows python programs to access SGI imglib image The imgfile module allows python programs to access SGI imglib image
......
\section{Standard module \sectcode{imghdr}} \section{Standard module \sectcode{imghdr}}
\label{module-imghdr}
\stmodindex{imghdr} \stmodindex{imghdr}
The \code{imghdr} module determines the type of image contained in a The \code{imghdr} module determines the type of image contained in a
...@@ -53,8 +54,8 @@ the test succeeded, or \code{None} if it failed. ...@@ -53,8 +54,8 @@ the test succeeded, or \code{None} if it failed.
Example: Example:
\begin{verbatim} \bcode\begin{verbatim}
>>> import imghdr >>> import imghdr
>>> imghdr.what('/tmp/bass.gif') >>> imghdr.what('/tmp/bass.gif')
'gif' 'gif'
\end{verbatim} \end{verbatim}\ecode
\section{Built-in Module \sectcode{imp}} \section{Built-in Module \sectcode{imp}}
\label{module-imp}
\bimodindex{imp} \bimodindex{imp}
\index{import} \index{import}
...@@ -132,7 +133,7 @@ The module was found as dynamically loadable shared library. ...@@ -132,7 +133,7 @@ The module was found as dynamically loadable shared library.
\subsection{Examples} \subsection{Examples}
The following function emulates the default import statement: The following function emulates the default import statement:
\begin{verbatim} \bcode\begin{verbatim}
import imp import imp
import sys import sys
...@@ -171,4 +172,4 @@ def __import__(name, globals=None, locals=None, fromlist=None): ...@@ -171,4 +172,4 @@ def __import__(name, globals=None, locals=None, fromlist=None):
finally: finally:
# Since we may exit via an exception, close fp explicitly. # Since we may exit via an exception, close fp explicitly.
fp.close() fp.close()
\end{verbatim} \end{verbatim}\ecode
\section{Built-in Module \sectcode{jpeg}} \section{Built-in Module \sectcode{jpeg}}
\label{module-jpeg}
\bimodindex{jpeg} \bimodindex{jpeg}
The module \code{jpeg} provides access to the jpeg compressor and The module \code{jpeg} provides access to the jpeg compressor and
......
\section{Standard Module \sectcode{mailcap}} \section{Standard Module \sectcode{mailcap}}
\label{module-mailcap}
\stmodindex{mailcap} \stmodindex{mailcap}
\renewcommand{\indexsubitem}{(in module mailcap)} \renewcommand{\indexsubitem}{(in module mailcap)}
...@@ -67,9 +68,9 @@ will override settings in the system mailcap files ...@@ -67,9 +68,9 @@ will override settings in the system mailcap files
\end{funcdesc} \end{funcdesc}
An example usage: An example usage:
\begin{verbatim} \bcode\begin{verbatim}
>>> import mailcap >>> import mailcap
>>> d=mailcap.getcaps() >>> d=mailcap.getcaps()
>>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223') >>> mailcap.findmatch(d, 'video/mpeg', filename='/tmp/tmp1223')
('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'}) ('xmpeg /tmp/tmp1223', {'view': 'xmpeg %s'})
\end{verbatim} \end{verbatim}\ecode
\section{Built-in Module \sectcode{__main__}} \section{Built-in Module \sectcode{__main__}}
\label{module-main}
\bimodindex{__main__} \bimodindex{__main__}
This module represents the (otherwise anonymous) scope in which the This module represents the (otherwise anonymous) scope in which the
interpreter's main program executes --- commands read either from interpreter's main program executes --- commands read either from
......
\section{Built-in Module \sectcode{marshal}} \section{Built-in Module \sectcode{marshal}}
\label{module-marshal}
\bimodindex{marshal} \bimodindex{marshal}
This module contains functions that can read and write Python This module contains functions that can read and write Python
......
\section{Built-in Module \sectcode{math}} \section{Built-in Module \sectcode{math}}
\label{module-math}
\bimodindex{math} \bimodindex{math}
\renewcommand{\indexsubitem}{(in module math)} \renewcommand{\indexsubitem}{(in module math)}
...@@ -70,3 +71,7 @@ The module also defines two mathematical constants: ...@@ -70,3 +71,7 @@ The module also defines two mathematical constants:
\else \else
\code{pi} and \code{e}. \code{pi} and \code{e}.
\fi \fi
\begin{seealso}
\seealso{cmath}{versions of these functions that can handle complex numbers}
\end{seealso}
\section{Built-in Module \sectcode{md5}} \section{Built-in Module \sectcode{md5}}
\label{module-md5}
\bimodindex{md5} \bimodindex{md5}
This module implements the interface to RSA's MD5 message digest This module implements the interface to RSA's MD5 message digest
...@@ -21,14 +22,14 @@ the spammish repetition"}: ...@@ -21,14 +22,14 @@ the spammish repetition"}:
>>> m.digest() >>> m.digest()
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351' '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
\end{verbatim}\ecode \end{verbatim}\ecode
%
More condensed: More condensed:
\bcode\begin{verbatim} \bcode\begin{verbatim}
>>> md5.new("Nobody inspects the spammish repetition").digest() >>> md5.new("Nobody inspects the spammish repetition").digest()
'\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351' '\273d\234\203\335\036\245\311\331\336\311\241\215\360\377\351'
\end{verbatim}\ecode \end{verbatim}\ecode
%
\renewcommand{\indexsubitem}{(in module md5)} \renewcommand{\indexsubitem}{(in module md5)}
\begin{funcdesc}{new}{\optional{arg}} \begin{funcdesc}{new}{\optional{arg}}
......
\section{Standard Module \sectcode{mimetools}} \section{Standard Module \sectcode{mimetools}}
\label{module-mimetools}
\stmodindex{mimetools} \stmodindex{mimetools}
\renewcommand{\indexsubitem}{(in module mimetools)} \renewcommand{\indexsubitem}{(in module mimetools)}
......
\section{Built-in Module \sectcode{mpz}} \section{Built-in Module \sectcode{mpz}}
\label{module-mpz}
\bimodindex{mpz} \bimodindex{mpz}
This is an optional module. It is only available when Python is This is an optional module. It is only available when Python is
......
\section{Standard Module \sectcode{nntplib}} \section{Standard Module \sectcode{nntplib}}
\label{module-nntplib}
\stmodindex{nntplib} \stmodindex{nntplib}
\renewcommand{\indexsubitem}{(in module nntplib)} \renewcommand{\indexsubitem}{(in module nntplib)}
...@@ -13,7 +14,7 @@ statistics about a newsgroup and print the subjects of the last 10 ...@@ -13,7 +14,7 @@ statistics about a newsgroup and print the subjects of the last 10
articles: articles:
\small{ \small{
\begin{verbatim} \bcode\begin{verbatim}
>>> s = NNTP('news.cwi.nl') >>> s = NNTP('news.cwi.nl')
>>> resp, count, first, last, name = s.group('comp.lang.python') >>> resp, count, first, last, name = s.group('comp.lang.python')
>>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
...@@ -34,13 +35,13 @@ Group comp.lang.python has 59 articles, range 3742 to 3803 ...@@ -34,13 +35,13 @@ Group comp.lang.python has 59 articles, range 3742 to 3803
>>> s.quit() >>> s.quit()
'205 news.cwi.nl closing connection. Goodbye.' '205 news.cwi.nl closing connection. Goodbye.'
>>> >>>
\end{verbatim} \end{verbatim}\ecode
} }
To post an article from a file (this assumes that the article has To post an article from a file (this assumes that the article has
valid headers): valid headers):
\begin{verbatim} \bcode\begin{verbatim}
>>> s = NNTP('news.cwi.nl') >>> s = NNTP('news.cwi.nl')
>>> f = open('/tmp/article') >>> f = open('/tmp/article')
>>> s.post(f) >>> s.post(f)
...@@ -48,8 +49,8 @@ valid headers): ...@@ -48,8 +49,8 @@ valid headers):
>>> s.quit() >>> s.quit()
'205 news.cwi.nl closing connection. Goodbye.' '205 news.cwi.nl closing connection. Goodbye.'
>>> >>>
\end{verbatim} \end{verbatim}\ecode
%
The module itself defines the following items: The module itself defines the following items:
\begin{funcdesc}{NNTP}{host\optional{\, port}} \begin{funcdesc}{NNTP}{host\optional{\, port}}
......
...@@ -184,10 +184,10 @@ Delete the slice of a from index b to index c-1. ...@@ -184,10 +184,10 @@ Delete the slice of a from index b to index c-1.
Example: Build a dictionary that maps the ordinals from 0 to 256 to their Example: Build a dictionary that maps the ordinals from 0 to 256 to their
character equivalents. character equivalents.
\begin{verbatim} \bcode\begin{verbatim}
>>> import operator >>> import operator
>>> d = {} >>> d = {}
>>> keys = range(256) >>> keys = range(256)
>>> vals = map(chr, keys) >>> vals = map(chr, keys)
>>> map(operator.setitem, [d]*len(keys), keys, vals) >>> map(operator.setitem, [d]*len(keys), keys, vals)
\end{verbatim} \end{verbatim}\ecode
\section{Standard Module \sectcode{os}} \section{Standard Module \sectcode{os}}
\label{module-os}
\stmodindex{os} \stmodindex{os}
This module provides a more portable way of using operating system This module provides a more portable way of using operating system
......
\section{Standard Module \sectcode{panel}} \section{Standard Module \sectcode{panel}}
\label{module-panel}
\stmodindex{panel} \stmodindex{panel}
\strong{Please note:} The FORMS library, to which the \code{fl} module described \strong{Please note:} The FORMS library, to which the \code{fl} module described
......
...@@ -288,30 +288,30 @@ bytecode generation, the simplest operation is to do nothing. For ...@@ -288,30 +288,30 @@ bytecode generation, the simplest operation is to do nothing. For
this purpose, using the \code{parser} module to produce an this purpose, using the \code{parser} module to produce an
intermediate data structure is equivelent to the code intermediate data structure is equivelent to the code
\begin{verbatim} \bcode\begin{verbatim}
>>> code = compile('a + 5', 'eval') >>> code = compile('a + 5', 'eval')
>>> a = 5 >>> a = 5
>>> eval(code) >>> eval(code)
10 10
\end{verbatim} \end{verbatim}\ecode
%
The equivelent operation using the \code{parser} module is somewhat The equivelent operation using the \code{parser} module is somewhat
longer, and allows the intermediate internal parse tree to be retained longer, and allows the intermediate internal parse tree to be retained
as an AST object: as an AST object:
\begin{verbatim} \bcode\begin{verbatim}
>>> import parser >>> import parser
>>> ast = parser.expr('a + 5') >>> ast = parser.expr('a + 5')
>>> code = parser.compileast(ast) >>> code = parser.compileast(ast)
>>> a = 5 >>> a = 5
>>> eval(code) >>> eval(code)
10 10
\end{verbatim} \end{verbatim}\ecode
%
An application which needs both AST and code objects can package this An application which needs both AST and code objects can package this
code into readily available functions: code into readily available functions:
\begin{verbatim} \bcode\begin{verbatim}
import parser import parser
def load_suite(source_string): def load_suite(source_string):
...@@ -323,8 +323,8 @@ def load_expression(source_string): ...@@ -323,8 +323,8 @@ def load_expression(source_string):
ast = parser.expr(source_string) ast = parser.expr(source_string)
code = parser.compileast(ast) code = parser.compileast(ast)
return ast, code return ast, code
\end{verbatim} \end{verbatim}\ecode
%
\subsubsection{Information Discovery} \subsubsection{Information Discovery}
Some applications benefit from direct access to the parse tree. The Some applications benefit from direct access to the parse tree. The
...@@ -366,16 +366,16 @@ Consider the simplest case of interest when searching for docstrings: ...@@ -366,16 +366,16 @@ Consider the simplest case of interest when searching for docstrings:
a module consisting of a docstring and nothing else. (See file a module consisting of a docstring and nothing else. (See file
\file{docstring.py}.) \file{docstring.py}.)
\begin{verbatim} \bcode\begin{verbatim}
"""Some documentation. """Some documentation.
""" """
\end{verbatim} \end{verbatim}\ecode
%
Using the interpreter to take a look at the parse tree, we find a Using the interpreter to take a look at the parse tree, we find a
bewildering mass of numbers and parentheses, with the documentation bewildering mass of numbers and parentheses, with the documentation
buried deep in nested tuples. buried deep in nested tuples.
\begin{verbatim} \bcode\begin{verbatim}
>>> import parser >>> import parser
>>> import pprint >>> import pprint
>>> ast = parser.suite(open('docstring.py').read()) >>> ast = parser.suite(open('docstring.py').read())
...@@ -403,8 +403,8 @@ buried deep in nested tuples. ...@@ -403,8 +403,8 @@ buried deep in nested tuples.
(4, ''))), (4, ''))),
(4, ''), (4, ''),
(0, '')) (0, ''))
\end{verbatim} \end{verbatim}\ecode
%
The numbers at the first element of each node in the tree are the node The numbers at the first element of each node in the tree are the node
types; they map directly to terminal and non-terminal symbols in the types; they map directly to terminal and non-terminal symbols in the
grammar. Unfortunately, they are represented as integers in the grammar. Unfortunately, they are represented as integers in the
...@@ -442,7 +442,7 @@ form, allowing a simple variable representation to be ...@@ -442,7 +442,7 @@ form, allowing a simple variable representation to be
the pattern matching, returning a boolean and a dictionary of variable the pattern matching, returning a boolean and a dictionary of variable
name to value mappings. (See file \file{example.py}.) name to value mappings. (See file \file{example.py}.)
\begin{verbatim} \bcode\begin{verbatim}
from types import ListType, TupleType from types import ListType, TupleType
def match(pattern, data, vars=None): def match(pattern, data, vars=None):
...@@ -460,13 +460,13 @@ def match(pattern, data, vars=None): ...@@ -460,13 +460,13 @@ def match(pattern, data, vars=None):
if not same: if not same:
break break
return same, vars return same, vars
\end{verbatim} \end{verbatim}\ecode
%
Using this simple representation for syntactic variables and the symbolic Using this simple representation for syntactic variables and the symbolic
node types, the pattern for the candidate docstring subtrees becomes node types, the pattern for the candidate docstring subtrees becomes
fairly readable. (See file \file{example.py}.) fairly readable. (See file \file{example.py}.)
\begin{verbatim} \bcode\begin{verbatim}
import symbol import symbol
import token import token
...@@ -493,19 +493,19 @@ DOCSTRING_STMT_PATTERN = ( ...@@ -493,19 +493,19 @@ DOCSTRING_STMT_PATTERN = (
)))))))))))))))), )))))))))))))))),
(token.NEWLINE, '') (token.NEWLINE, '')
)) ))
\end{verbatim} \end{verbatim}\ecode
%
Using the \code{match()} function with this pattern, extracting the Using the \code{match()} function with this pattern, extracting the
module docstring from the parse tree created previously is easy: module docstring from the parse tree created previously is easy:
\begin{verbatim} \bcode\begin{verbatim}
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1]) >>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
>>> found >>> found
1 1
>>> vars >>> vars
{'docstring': '"""Some documentation.\012"""'} {'docstring': '"""Some documentation.\012"""'}
\end{verbatim} \end{verbatim}\ecode
%
Once specific data can be extracted from a location where it is Once specific data can be extracted from a location where it is
expected, the question of where information can be expected expected, the question of where information can be expected
needs to be answered. When dealing with docstrings, the answer is needs to be answered. When dealing with docstrings, the answer is
...@@ -567,7 +567,7 @@ grammar, but the method which recursively creates new information ...@@ -567,7 +567,7 @@ grammar, but the method which recursively creates new information
objects requires further examination. Here is the relevant part of objects requires further examination. Here is the relevant part of
the \code{SuiteInfoBase} definition from \file{example.py}: the \code{SuiteInfoBase} definition from \file{example.py}:
\begin{verbatim} \bcode\begin{verbatim}
class SuiteInfoBase: class SuiteInfoBase:
_docstring = '' _docstring = ''
_name = '' _name = ''
...@@ -597,8 +597,8 @@ class SuiteInfoBase: ...@@ -597,8 +597,8 @@ class SuiteInfoBase:
elif cstmt[0] == symbol.classdef: elif cstmt[0] == symbol.classdef:
name = cstmt[2][1] name = cstmt[2][1]
self._class_info[name] = ClassInfo(cstmt) self._class_info[name] = ClassInfo(cstmt)
\end{verbatim} \end{verbatim}\ecode
%
After initializing some internal state, the constructor calls the After initializing some internal state, the constructor calls the
\code{_extract_info()} method. This method performs the bulk of the \code{_extract_info()} method. This method performs the bulk of the
information extraction which takes place in the entire example. The information extraction which takes place in the entire example. The
...@@ -611,21 +611,21 @@ the ``short form'' or the ``long form.'' The short form is used when ...@@ -611,21 +611,21 @@ the ``short form'' or the ``long form.'' The short form is used when
the code block is on the same line as the definition of the code the code block is on the same line as the definition of the code
block, as in block, as in
\begin{verbatim} \bcode\begin{verbatim}
def square(x): "Square an argument."; return x ** 2 def square(x): "Square an argument."; return x ** 2
\end{verbatim} \end{verbatim}\ecode
%
while the long form uses an indented block and allows nested while the long form uses an indented block and allows nested
definitions: definitions:
\begin{verbatim} \bcode\begin{verbatim}
def make_power(exp): def make_power(exp):
"Make a function that raises an argument to the exponent `exp'." "Make a function that raises an argument to the exponent `exp'."
def raiser(x, y=exp): def raiser(x, y=exp):
return x ** y return x ** y
return raiser return raiser
\end{verbatim} \end{verbatim}\ecode
%
When the short form is used, the code block may contain a docstring as When the short form is used, the code block may contain a docstring as
the first, and possibly only, \code{small_stmt} element. The the first, and possibly only, \code{small_stmt} element. The
extraction of such a docstring is slightly different and requires only extraction of such a docstring is slightly different and requires only
...@@ -660,7 +660,7 @@ the real extraction algorithm remains common to all forms of code ...@@ -660,7 +660,7 @@ the real extraction algorithm remains common to all forms of code
blocks. A high-level function can be used to extract the complete set blocks. A high-level function can be used to extract the complete set
of information from a source file. (See file \file{example.py}.) of information from a source file. (See file \file{example.py}.)
\begin{verbatim} \bcode\begin{verbatim}
def get_docs(fileName): def get_docs(fileName):
source = open(fileName).read() source = open(fileName).read()
import os import os
...@@ -669,8 +669,8 @@ def get_docs(fileName): ...@@ -669,8 +669,8 @@ def get_docs(fileName):
ast = parser.suite(source) ast = parser.suite(source)
tup = parser.ast2tuple(ast) tup = parser.ast2tuple(ast)
return ModuleInfo(tup, basename) return ModuleInfo(tup, basename)
\end{verbatim} \end{verbatim}\ecode
%
This provides an easy-to-use interface to the documentation of a This provides an easy-to-use interface to the documentation of a
module. If information is required which is not extracted by the code module. If information is required which is not extracted by the code
of this example, the code may be extended at clearly defined points to of this example, the code may be extended at clearly defined points to
......
...@@ -29,7 +29,7 @@ specific modules). ...@@ -29,7 +29,7 @@ specific modules).
The debugger's prompt is ``\code{(Pdb) }''. The debugger's prompt is ``\code{(Pdb) }''.
Typical usage to run a program under control of the debugger is: Typical usage to run a program under control of the debugger is:
\begin{verbatim} \bcode\begin{verbatim}
>>> import pdb >>> import pdb
>>> import mymodule >>> import mymodule
>>> pdb.run('mymodule.test()') >>> pdb.run('mymodule.test()')
...@@ -40,15 +40,15 @@ Typical usage to run a program under control of the debugger is: ...@@ -40,15 +40,15 @@ Typical usage to run a program under control of the debugger is:
NameError: 'spam' NameError: 'spam'
> <string>(1)?() > <string>(1)?()
(Pdb) (Pdb)
\end{verbatim} \end{verbatim}\ecode
%
\code{pdb.py} can also be invoked as \code{pdb.py} can also be invoked as
a script to debug other scripts. For example: a script to debug other scripts. For example:
\code{python /usr/local/lib/python1.4/pdb.py myscript.py} \code{python /usr/local/lib/python1.4/pdb.py myscript.py}
Typical usage to inspect a crashed program is: Typical usage to inspect a crashed program is:
\begin{verbatim} \bcode\begin{verbatim}
>>> import pdb >>> import pdb
>>> import mymodule >>> import mymodule
>>> mymodule.test() >>> mymodule.test()
...@@ -63,8 +63,8 @@ NameError: spam ...@@ -63,8 +63,8 @@ NameError: spam
> ./mymodule.py(3)test2() > ./mymodule.py(3)test2()
-> print spam -> print spam
(Pdb) (Pdb)
\end{verbatim} \end{verbatim}\ecode
%
The module defines the following functions; each enters the debugger The module defines the following functions; each enters the debugger
in a slightly different way: in a slightly different way:
...@@ -224,11 +224,11 @@ The exclamation point can be omitted unless the first word ...@@ -224,11 +224,11 @@ The exclamation point can be omitted unless the first word
of the statement resembles a debugger command. of the statement resembles a debugger command.
To set a global variable, you can prefix the assignment To set a global variable, you can prefix the assignment
command with a ``\code{global}'' command on the same line, e.g.: command with a ``\code{global}'' command on the same line, e.g.:
\begin{verbatim} \bcode\begin{verbatim}
(Pdb) global list_options; list_options = ['-l'] (Pdb) global list_options; list_options = ['-l']
(Pdb) (Pdb)
\end{verbatim} \end{verbatim}\ecode
%
\item[q(uit)] \item[q(uit)]
Quit from the debugger. Quit from the debugger.
......
\section{Standard Module \sectcode{pickle}} \section{Standard Module \sectcode{pickle}}
\label{module-pickle}
\stmodindex{pickle} \stmodindex{pickle}
\index{persistency} \index{persistency}
\indexii{persistent}{objects} \indexii{persistent}{objects}
...@@ -133,30 +134,30 @@ The interface can be summarized as follows. ...@@ -133,30 +134,30 @@ The interface can be summarized as follows.
To pickle an object \code{x} onto a file \code{f}, open for writing: To pickle an object \code{x} onto a file \code{f}, open for writing:
\begin{verbatim} \bcode\begin{verbatim}
p = pickle.Pickler(f) p = pickle.Pickler(f)
p.dump(x) p.dump(x)
\end{verbatim} \end{verbatim}\ecode
%
A shorthand for this is: A shorthand for this is:
\begin{verbatim} \bcode\begin{verbatim}
pickle.dump(x, f) pickle.dump(x, f)
\end{verbatim} \end{verbatim}\ecode
%
To unpickle an object \code{x} from a file \code{f}, open for reading: To unpickle an object \code{x} from a file \code{f}, open for reading:
\begin{verbatim} \bcode\begin{verbatim}
u = pickle.Unpickler(f) u = pickle.Unpickler(f)
x = u.load() x = u.load()
\end{verbatim} \end{verbatim}\ecode
%
A shorthand is: A shorthand is:
\begin{verbatim} \bcode\begin{verbatim}
x = pickle.load(f) x = pickle.load(f)
\end{verbatim} \end{verbatim}\ecode
%
The \code{Pickler} class only calls the method \code{f.write} with a The \code{Pickler} class only calls the method \code{f.write} with a
string argument. The \code{Unpickler} calls the methods \code{f.read} string argument. The \code{Unpickler} calls the methods \code{f.read}
(with an integer argument) and \code{f.readline} (without argument), (with an integer argument) and \code{f.readline} (without argument),
......
\section{Built-in Module \sectcode{posix}} \section{Built-in Module \sectcode{posix}}
\label{module-posix}
\bimodindex{posix} \bimodindex{posix}
This module provides access to operating system functionality that is This module provides access to operating system functionality that is
......
\section{Standard Module \sectcode{posixpath}} \section{Standard Module \sectcode{posixpath}}
\label{module-posixpath}
\stmodindex{posixpath} \stmodindex{posixpath}
This module implements some useful functions on POSIX pathnames. This module implements some useful functions on POSIX pathnames.
......
This diff is collapsed.
\section{Built-in Module \sectcode{pwd}} \section{Built-in Module \sectcode{pwd}}
\label{module-pwd}
\bimodindex{pwd} \bimodindex{pwd}
This module provides access to the \UNIX{} password database. This module provides access to the \UNIX{} password database.
......
\section{Standard Module \sectcode{quopri}} \section{Standard Module \sectcode{quopri}}
\label{module-quopri}
\stmodindex{quopri} \stmodindex{quopri}
This module performs quoted-printable transport encoding and decoding, This module performs quoted-printable transport encoding and decoding,
......
\section{Standard Module \sectcode{rand}} \section{Standard Module \sectcode{rand}}
\label{module-rand}
\stmodindex{rand} \stmodindex{rand}
The \code{rand} module simulates the C library's \code{rand()} The \code{rand} module simulates the C library's \code{rand()}
...@@ -20,3 +21,7 @@ Set a starting seed value for the random number generator; \var{seed} ...@@ -20,3 +21,7 @@ Set a starting seed value for the random number generator; \var{seed}
can be an arbitrary integer. can be an arbitrary integer.
\end{funcdesc} \end{funcdesc}
\begin{seealso}
\seemodule{whrandom}{the standard Python random number generator}
\end{seealso}
\section{Standard Module \sectcode{random}} \section{Standard Module \sectcode{random}}
\label{module-random}
\stmodindex{random} \stmodindex{random}
This module implements pseudo-random number generators for various This module implements pseudo-random number generators for various
...@@ -69,3 +70,8 @@ then or equal to zero. If \var{kappa} is equal to zero, this ...@@ -69,3 +70,8 @@ then or equal to zero. If \var{kappa} is equal to zero, this
distribution reduces to a uniform random angle over the range 0 to distribution reduces to a uniform random angle over the range 0 to
\code{2*pi}. \code{2*pi}.
\end{funcdesc} \end{funcdesc}
\begin{seealso}
\seemodule{whrandom}{the standard Python random number generator}
\end{seealso}
\section{Built-in Module \sectcode{regex}} \section{Built-in Module \sectcode{regex}}
\label{module-regex}
\bimodindex{regex} \bimodindex{regex}
This module provides regular expression matching operations similar to This module provides regular expression matching operations similar to
...@@ -204,13 +205,13 @@ The module defines these functions, and an exception: ...@@ -204,13 +205,13 @@ The module defines these functions, and an exception:
prog = regex.compile(pat) prog = regex.compile(pat)
result = prog.match(str) result = prog.match(str)
\end{verbatim}\ecode \end{verbatim}\ecode
%
is equivalent to is equivalent to
\bcode\begin{verbatim} \bcode\begin{verbatim}
result = regex.match(pat, str) result = regex.match(pat, str)
\end{verbatim}\ecode \end{verbatim}\ecode
%
but the version using \code{compile()} is more efficient when multiple but the version using \code{compile()} is more efficient when multiple
regular expressions are used concurrently in a single program. (The regular expressions are used concurrently in a single program. (The
compiled version of the last pattern passed to \code{regex.match()} or compiled version of the last pattern passed to \code{regex.match()} or
......
\section{Standard Module \sectcode{regsub}} \section{Standard Module \sectcode{regsub}}
\label{module-regsub}
\stmodindex{regsub} \stmodindex{regsub}
This module defines a number of functions useful for working with This module defines a number of functions useful for working with
......
\section{Built-in Module \sectcode{resource}} \section{Built-in Module \sectcode{resource}}
\label{module-resource}
\bimodindex{resource} \bimodindex{resource}
This module provides basic mechanisms for measuring and controlling This module provides basic mechanisms for measuring and controlling
......
\section{Standard Module \sectcode{rexec}} \section{Standard Module \sectcode{rexec}}
\label{module-rexec}
\stmodindex{rexec} \stmodindex{rexec}
\renewcommand{\indexsubitem}{(in module rexec)} \renewcommand{\indexsubitem}{(in module rexec)}
...@@ -206,7 +207,7 @@ class TmpWriterRExec(rexec.RExec): ...@@ -206,7 +207,7 @@ class TmpWriterRExec(rexec.RExec):
else: raise IOError, "Illegal open() mode" else: raise IOError, "Illegal open() mode"
return open(file, mode, buf) return open(file, mode, buf)
\end{verbatim}\ecode \end{verbatim}\ecode
%
Notice that the above code will occasionally forbid a perfectly valid Notice that the above code will occasionally forbid a perfectly valid
filename; for example, code in the restricted environment won't be filename; for example, code in the restricted environment won't be
able to open a file called \file{/tmp/foo/../bar}. To fix this, the able to open a file called \file{/tmp/foo/../bar}. To fix this, the
......
\section{Standard Module \sectcode{rfc822}} \section{Standard Module \sectcode{rfc822}}
\label{module-rfc822}
\stmodindex{rfc822} \stmodindex{rfc822}
\renewcommand{\indexsubitem}{(in module rfc822)} \renewcommand{\indexsubitem}{(in module rfc822)}
......
\section{Built-in Module \sectcode{rgbimg}} \section{Built-in Module \sectcode{rgbimg}}
\label{module-rgbimg}
\bimodindex{rgbimg} \bimodindex{rgbimg}
The rgbimg module allows python programs to access SGI imglib image The rgbimg module allows python programs to access SGI imglib image
......
\section{Built-in Module \sectcode{rotor}} \section{Built-in Module \sectcode{rotor}}
\label{module-rotor}
\bimodindex{rotor} \bimodindex{rotor}
This module implements a rotor-based encryption algorithm, contributed by This module implements a rotor-based encryption algorithm, contributed by
...@@ -79,7 +80,7 @@ An example usage: ...@@ -79,7 +80,7 @@ An example usage:
'l(\315' 'l(\315'
>>> del rt >>> del rt
\end{verbatim}\ecode \end{verbatim}\ecode
%
The module's code is not an exact simulation of the original Enigma device; The module's code is not an exact simulation of the original Enigma device;
it implements the rotor encryption scheme differently from the original. The it implements the rotor encryption scheme differently from the original. The
most important difference is that in the original Enigma, there were only 5 most important difference is that in the original Enigma, there were only 5
......
\section{Built-in Module \sectcode{select}} \section{Built-in Module \sectcode{select}}
\label{module-select}
\bimodindex{select} \bimodindex{select}
This module provides access to the function \code{select} available in This module provides access to the function \code{select} available in
......
\section{Standard Module \sectcode{sgmllib}} \section{Standard Module \sectcode{sgmllib}}
\label{module-sgmllib}
\stmodindex{sgmllib} \stmodindex{sgmllib}
\index{SGML} \index{SGML}
......
\section{Standard Module \sectcode{shelve}} \section{Standard Module \sectcode{shelve}}
\label{module-shelve}
\stmodindex{shelve} \stmodindex{shelve}
\stmodindex{pickle} \stmodindex{pickle}
\bimodindex{dbm} \bimodindex{dbm}
...@@ -14,7 +15,7 @@ sub-objects. The keys are ordinary strings. ...@@ -14,7 +15,7 @@ sub-objects. The keys are ordinary strings.
To summarize the interface (\code{key} is a string, \code{data} is an To summarize the interface (\code{key} is a string, \code{data} is an
arbitrary object): arbitrary object):
\begin{verbatim} \bcode\begin{verbatim}
import shelve import shelve
d = shelve.open(filename) # open, with (g)dbm filename -- no suffix d = shelve.open(filename) # open, with (g)dbm filename -- no suffix
...@@ -29,8 +30,8 @@ flag = d.has_key(key) # true if the key exists ...@@ -29,8 +30,8 @@ flag = d.has_key(key) # true if the key exists
list = d.keys() # a list of all existing keys (slow!) list = d.keys() # a list of all existing keys (slow!)
d.close() # close it d.close() # close it
\end{verbatim} \end{verbatim}\ecode
%
Restrictions: Restrictions:
\begin{itemize} \begin{itemize}
......
\section{Built-in Module \sectcode{signal}} \section{Built-in Module \sectcode{signal}}
\label{module-signal}
\bimodindex{signal} \bimodindex{signal}
This module provides mechanisms to use signal handlers in Python. This module provides mechanisms to use signal handlers in Python.
......
\section{Standard Module \sectcode{site}} \section{Standard Module \sectcode{site}}
\label{module-site}
\stmodindex{site} \stmodindex{site}
Scripts or modules that need to use site-specific modules should Scripts or modules that need to use site-specific modules should
......
\section{Built-in Module \sectcode{socket}} \section{Built-in Module \sectcode{socket}}
\label{module-socket}
\bimodindex{socket} \bimodindex{socket}
This module provides access to the BSD {\em socket} interface. This module provides access to the BSD {\em socket} interface.
...@@ -336,7 +337,7 @@ while 1: ...@@ -336,7 +337,7 @@ while 1:
conn.send(data) conn.send(data)
conn.close() conn.close()
\end{verbatim}\ecode \end{verbatim}\ecode
%
\bcode\begin{verbatim} \bcode\begin{verbatim}
# Echo client program # Echo client program
from socket import * from socket import *
...@@ -349,3 +350,7 @@ data = s.recv(1024) ...@@ -349,3 +350,7 @@ data = s.recv(1024)
s.close() s.close()
print 'Received', `data` print 'Received', `data`
\end{verbatim}\ecode \end{verbatim}\ecode
%
\begin{seealso}
\seemodule{SocketServer}{classes that simplify writing network servers}
\end{seealso}
\section{Standard Module \sectcode{soundex}} \section{Standard Module \sectcode{soundex}}
\label{module-soundex}
\stmodindex{soundex} \stmodindex{soundex}
\renewcommand{\indexsubitem}{(in module soundex)} \renewcommand{\indexsubitem}{(in module soundex)}
......
...@@ -81,7 +81,7 @@ Time of creation. ...@@ -81,7 +81,7 @@ Time of creation.
Example: Example:
\begin{verbatim} \bcode\begin{verbatim}
import os, sys import os, sys
from stat import * from stat import *
...@@ -103,4 +103,4 @@ def f(file): ...@@ -103,4 +103,4 @@ def f(file):
print 'frobbed', file print 'frobbed', file
if __name__ == '__main__': process(sys.argv[1], f) if __name__ == '__main__': process(sys.argv[1], f)
\end{verbatim} \end{verbatim}\ecode
...@@ -774,7 +774,7 @@ def main(): ...@@ -774,7 +774,7 @@ def main():
main() main()
\end{verbatim}\ecode \end{verbatim}\ecode
%
\section{Standard Module \sectcode{stdwinevents}} \section{Standard Module \sectcode{stdwinevents}}
\stmodindex{stdwinevents} \stmodindex{stdwinevents}
...@@ -788,7 +788,7 @@ Suggested usage is ...@@ -788,7 +788,7 @@ Suggested usage is
>>> from stdwinevents import * >>> from stdwinevents import *
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
\section{Standard Module \sectcode{rect}} \section{Standard Module \sectcode{rect}}
\stmodindex{rect} \stmodindex{rect}
...@@ -801,7 +801,7 @@ For example, the rectangle ...@@ -801,7 +801,7 @@ For example, the rectangle
\bcode\begin{verbatim} \bcode\begin{verbatim}
(10, 20), (90, 80) (10, 20), (90, 80)
\end{verbatim}\ecode \end{verbatim}\ecode
%
is a rectangle whose left, top, right and bottom edges are 10, 20, 90 is a rectangle whose left, top, right and bottom edges are 10, 20, 90
and 80, respectively. and 80, respectively.
Note that the positive vertical axis points down (as in Note that the positive vertical axis points down (as in
......
\section{Standard Module \sectcode{string}} \section{Standard Module \sectcode{string}}
\label{module-string}
\stmodindex{string} \stmodindex{string}
......
\section{Built-in Module \sectcode{struct}} \section{Built-in Module \sectcode{struct}}
\label{module-struct}
\bimodindex{struct} \bimodindex{struct}
\indexii{C}{structures} \indexii{C}{structures}
...@@ -126,7 +127,7 @@ big-endian machine): ...@@ -126,7 +127,7 @@ big-endian machine):
8 8
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
Hint: to align the end of a structure to the alignment requirement of Hint: to align the end of a structure to the alignment requirement of
a particular type, end the format with the code for that type with a a particular type, end the format with the code for that type with a
repeat count of zero, e.g.\ the format \code{'llh0l'} specifies two repeat count of zero, e.g.\ the format \code{'llh0l'} specifies two
......
\section{Built-in Module \sectcode{sys}} \section{Built-in Module \sectcode{sys}}
\label{module-sys}
\bimodindex{sys} \bimodindex{sys}
This module provides access to some variables used or maintained by the This module provides access to some variables used or maintained by the
......
\section{Built-in Module \sectcode{syslog}} \section{Built-in Module \sectcode{syslog}}
\label{module-syslog}
\bimodindex{syslog} \bimodindex{syslog}
This module provides an interface to the Unix \code{syslog} library This module provides an interface to the Unix \code{syslog} library
......
\section{Standard Module \sectcode{tempfile}} \section{Standard Module \sectcode{tempfile}}
\label{module-tempfile}
\stmodindex{tempfile} \stmodindex{tempfile}
\indexii{temporary}{file name} \indexii{temporary}{file name}
\indexii{temporary}{file} \indexii{temporary}{file}
......
...@@ -96,13 +96,13 @@ failure. ...@@ -96,13 +96,13 @@ failure.
Example: Example:
\begin{verbatim} \bcode\begin{verbatim}
>>> import spam >>> import spam
>>> can = spam.open('/etc/passwd') >>> can = spam.open('/etc/passwd')
>>> can.empty() >>> can.empty()
>>> can.close() >>> can.close()
\end{verbatim} \end{verbatim}\ecode
%
% ==== 5. ==== % ==== 5. ====
% If your module defines new object types (for a built-in module) or % If your module defines new object types (for a built-in module) or
% classes (for a module written in Python), you should list the % classes (for a module written in Python), you should list the
......
\section{Built-in Module \sectcode{termios}} \section{Built-in Module \sectcode{termios}}
\label{module-termios}
\bimodindex{termios} \bimodindex{termios}
\indexii{Posix}{I/O control} \indexii{Posix}{I/O control}
\indexii{tty}{I/O control} \indexii{tty}{I/O control}
...@@ -76,7 +77,7 @@ Note the technique using a separate \code{termios.tcgetattr()} call ...@@ -76,7 +77,7 @@ Note the technique using a separate \code{termios.tcgetattr()} call
and a \code{try \ldots{} finally} statement to ensure that the old tty and a \code{try \ldots{} finally} statement to ensure that the old tty
attributes are restored exactly no matter what happens: attributes are restored exactly no matter what happens:
\begin{verbatim} \bcode\begin{verbatim}
def getpass(prompt = "Password: "): def getpass(prompt = "Password: "):
import termios, TERMIOS, sys import termios, TERMIOS, sys
fd = sys.stdin.fileno() fd = sys.stdin.fileno()
...@@ -89,9 +90,8 @@ def getpass(prompt = "Password: "): ...@@ -89,9 +90,8 @@ def getpass(prompt = "Password: "):
finally: finally:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old) termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
return passwd return passwd
\end{verbatim} \end{verbatim}\ecode
%
\section{Standard Module \sectcode{TERMIOS}} \section{Standard Module \sectcode{TERMIOS}}
\stmodindex{TERMIOS} \stmodindex{TERMIOS}
\indexii{Posix}{I/O control} \indexii{Posix}{I/O control}
......
\section{Built-in Module \sectcode{thread}} \section{Built-in Module \sectcode{thread}}
\label{module-thread}
\bimodindex{thread} \bimodindex{thread}
This module provides low-level primitives for working with multiple This module provides low-level primitives for working with multiple
......
\section{Built-in Module \sectcode{time}} \section{Built-in Module \sectcode{time}}
\label{module-time}
\bimodindex{time} \bimodindex{time}
This module provides various time-related functions. This module provides various time-related functions.
......
\section{Standard Module \sectcode{traceback}} \section{Standard Module \sectcode{traceback}}
\label{module-traceback}
\stmodindex{traceback} \stmodindex{traceback}
\renewcommand{\indexsubitem}{(in module traceback)} \renewcommand{\indexsubitem}{(in module traceback)}
......
\section{Standard Module \sectcode{types}} \section{Standard Module \sectcode{types}}
\label{module-types}
\stmodindex{types} \stmodindex{types}
\renewcommand{\indexsubitem}{(in module types)} \renewcommand{\indexsubitem}{(in module types)}
...@@ -13,15 +14,15 @@ all end in \code{Type}. ...@@ -13,15 +14,15 @@ all end in \code{Type}.
Typical use is for functions that do different things depending on Typical use is for functions that do different things depending on
their argument types, like the following: their argument types, like the following:
\begin{verbatim} \bcode\begin{verbatim}
from types import * from types import *
def delete(list, item): def delete(list, item):
if type(item) is IntType: if type(item) is IntType:
del list[item] del list[item]
else: else:
list.remove(item) list.remove(item)
\end{verbatim} \end{verbatim}\ecode
%
The module defines the following names: The module defines the following names:
\begin{datadesc}{NoneType} \begin{datadesc}{NoneType}
......
\section{Standard Module \sectcode{urllib}} \section{Standard Module \sectcode{urllib}}
\label{module-urllib}
\stmodindex{urllib} \stmodindex{urllib}
\index{WWW} \index{WWW}
\index{World-Wide Web} \index{World-Wide Web}
......
\section{Standard Module \sectcode{urlparse}} \section{Standard Module \sectcode{urlparse}}
\label{module-urlparse}
\stmodindex{urlparse} \stmodindex{urlparse}
\index{WWW} \index{WWW}
\index{World-Wide Web} \index{World-Wide Web}
...@@ -34,16 +35,16 @@ retained if present. ...@@ -34,16 +35,16 @@ retained if present.
Example: Example:
\begin{verbatim} \bcode\begin{verbatim}
urlparse('http://www.cwi.nl:80/%7Eguido/Python.html') urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
\end{verbatim} \end{verbatim}\ecode
%
yields the tuple yields the tuple
\begin{verbatim} \bcode\begin{verbatim}
('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '') ('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')
\end{verbatim} \end{verbatim}\ecode
%
If the \var{default_scheme} argument is specified, it gives the If the \var{default_scheme} argument is specified, it gives the
default addressing scheme, to be used only if the URL string does not default addressing scheme, to be used only if the URL string does not
specify one. The default value for this argument is the empty string. specify one. The default value for this argument is the empty string.
...@@ -69,16 +70,16 @@ components in the relative URL. ...@@ -69,16 +70,16 @@ components in the relative URL.
Example: Example:
\begin{verbatim} \bcode\begin{verbatim}
urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html') urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
\end{verbatim} \end{verbatim}\ecode
%
yields the string yields the string
\begin{verbatim} \bcode\begin{verbatim}
'http://www.cwi.nl/%7Eguido/FAQ.html' 'http://www.cwi.nl/%7Eguido/FAQ.html'
\end{verbatim} \end{verbatim}\ecode
%
The \var{allow_fragments} argument has the same meaning as for The \var{allow_fragments} argument has the same meaning as for
\code{urlparse}. \code{urlparse}.
\end{funcdesc} \end{funcdesc}
\section{Standard Module \sectcode{whichdb}} \section{Standard Module \sectcode{whichdb}}
\label{module-whichdb}
\stmodindex{whichdb} \stmodindex{whichdb}
The single function in this module attempts to guess which of the The single function in this module attempts to guess which of the
......
\section{Standard Module \sectcode{whrandom}} \section{Standard Module \sectcode{whrandom}}
\label{module-whrandom}
\stmodindex{whrandom} \stmodindex{whrandom}
This module implements a Wichmann-Hill pseudo-random number generator This module implements a Wichmann-Hill pseudo-random number generator
...@@ -36,7 +37,14 @@ When imported, the \code{whrandom} module also creates an instance of ...@@ -36,7 +37,14 @@ When imported, the \code{whrandom} module also creates an instance of
the \code{whrandom} class, and makes the methods of that instance the \code{whrandom} class, and makes the methods of that instance
available at the module level. Therefore one can write either available at the module level. Therefore one can write either
\code{N = whrandom.random()} or: \code{N = whrandom.random()} or:
\begin{verbatim} \bcode\begin{verbatim}
generator = whrandom.whrandom() generator = whrandom.whrandom()
N = generator.random() N = generator.random()
\end{verbatim} \end{verbatim}\ecode
%
\begin{seealso}
\seemodule{random}{generators for various random distributions}
\seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
An efficient and portable pseudo-random number generator'',
Applied Statistics 31 (1982) 188-190}
\end{seealso}
\section{Standard module \sectcode{xdrlib}} \section{Standard module \sectcode{xdrlib}}
\label{module-xdrlib}
\stmodindex{xdrlib} \stmodindex{xdrlib}
\index{XDR} \index{XDR}
...@@ -221,15 +222,15 @@ variables. ...@@ -221,15 +222,15 @@ variables.
Here is an example of how you would catch one of these exceptions: Here is an example of how you would catch one of these exceptions:
\begin{verbatim} \bcode\begin{verbatim}
import xdrlib import xdrlib
p = xdrlib.Packer() p = xdrlib.Packer()
try: try:
p.pack_double(8.01) p.pack_double(8.01)
except xdrlib.ConversionError, instance: except xdrlib.ConversionError, instance:
print 'packing the double failed:', instance.msg print 'packing the double failed:', instance.msg
\end{verbatim} \end{verbatim}\ecode
%
\subsection{Supporting Floating Point Data} \subsection{Supporting Floating Point Data}
Packing and unpacking floating point data, Packing and unpacking floating point data,
......
\section{Built-in Module \sectcode{zlib}} \section{Built-in Module \sectcode{zlib}}
\label{module-zlib}
\bimodindex{zlib} \bimodindex{zlib}
For applications that require data compression, the functions in this For applications that require data compression, the functions in this
...@@ -95,5 +96,8 @@ uncompressed output is returned. After calling \code{flush()}, the ...@@ -95,5 +96,8 @@ uncompressed output is returned. After calling \code{flush()}, the
action is to delete the object. action is to delete the object.
\end{funcdesc} \end{funcdesc}
\begin{seealso}
\seemodule{gzip}{reading and writing \file{gzip}-format files}
\end{seealso}
\section{Standard Module \sectcode{aifc}} \section{Standard Module \sectcode{aifc}}
\label{module-aifc}
\stmodindex{aifc} \stmodindex{aifc}
This module provides support for reading and writing AIFF and AIFF-C This module provides support for reading and writing AIFF and AIFF-C
......
\section{Built-in Module \sectcode{al}} \section{Built-in Module \sectcode{al}}
\label{module-al}
\bimodindex{al} \bimodindex{al}
This module provides access to the audio facilities of the SGI Indy This module provides access to the audio facilities of the SGI Indy
......
...@@ -82,7 +82,7 @@ For example: ...@@ -82,7 +82,7 @@ For example:
aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a aa:1c:95:52:6a:fa/14(ff)/8e:ba:5b:8:11:1a
>>> >>>
\end{verbatim}\ecode \end{verbatim}\ecode
%
The following methods are defined for capability objects. The following methods are defined for capability objects.
\renewcommand{\indexsubitem}{(capability method)} \renewcommand{\indexsubitem}{(capability method)}
......
\section{Built-in Module \sectcode{array}} \section{Built-in Module \sectcode{array}}
\label{module-array}
\bimodindex{array} \bimodindex{array}
\index{arrays} \index{arrays}
......
\section{Built-in Module \sectcode{audio}} \section{Built-in Module \sectcode{audio}}
\label{module-audio}
\bimodindex{audio} \bimodindex{audio}
\strong{Note:} This module is obsolete, since the hardware to which it \strong{Note:} This module is obsolete, since the hardware to which it
......
\section{Built-in Module \sectcode{audioop}} \section{Built-in Module \sectcode{audioop}}
\label{module-audioop}
\bimodindex{audioop} \bimodindex{audioop}
The \code{audioop} module contains some useful operations on sound fragments. The \code{audioop} module contains some useful operations on sound fragments.
...@@ -210,7 +211,7 @@ def mul_stereo(sample, width, lfactor, rfactor): ...@@ -210,7 +211,7 @@ def mul_stereo(sample, width, lfactor, rfactor):
rsample = audioop.tostereo(rsample, width, 0, 1) rsample = audioop.tostereo(rsample, width, 0, 1)
return audioop.add(lsample, rsample, width) return audioop.add(lsample, rsample, width)
\end{verbatim}\ecode \end{verbatim}\ecode
%
If you use the ADPCM coder to build network packets and you want your If you use the ADPCM coder to build network packets and you want your
protocol to be stateless (i.e.\ to be able to tolerate packet loss) protocol to be stateless (i.e.\ to be able to tolerate packet loss)
you should not only transmit the data but also the state. Note that you should not only transmit the data but also the state. Note that
......
\section{Standard Module \sectcode{base64}} \section{Standard Module \sectcode{base64}}
\label{module-base64}
\stmodindex{base64} \stmodindex{base64}
This module perform base-64 encoding and decoding of arbitrary binary This module perform base-64 encoding and decoding of arbitrary binary
......
\section{Standard Module \sectcode{Bastion}} \section{Standard Module \sectcode{Bastion}}
\label{module-Bastion}
\stmodindex{Bastion} \stmodindex{Bastion}
\renewcommand{\indexsubitem}{(in module Bastion)} \renewcommand{\indexsubitem}{(in module Bastion)}
......
\section{Standard module \sectcode{binhex}} \section{Standard module \sectcode{binhex}}
\label{module-binhex}
\stmodindex{binhex} \stmodindex{binhex}
This module encodes and decodes files in binhex4 format, a format This module encodes and decodes files in binhex4 format, a format
......
\section{Built-in Module \sectcode{__builtin__}} \section{Built-in Module \sectcode{__builtin__}}
\label{module-builtin}
\bimodindex{__builtin__} \bimodindex{__builtin__}
This module provides direct access to all `built-in' identifiers of This module provides direct access to all `built-in' identifiers of
......
\section{Built-in Module \sectcode{cd}} \section{Built-in Module \sectcode{cd}}
\label{module-cd}
\bimodindex{cd} \bimodindex{cd}
This module provides an interface to the Silicon Graphics CD library. This module provides an interface to the Silicon Graphics CD library.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment