Index

Symbols
 
' (single quoted string delimiter) 46
- (subtraction operator), for numbers 47
- (unary minus operator) 352
!= (not equal) 97, 352
" (double quoted string delimiter) 45
# (comment header) 44
% (modulus operator)
     for numbers 352
     for strings 81, 360
& (bitwise and operator) 352
() (empty tuple) 64, 365
(tab character) 46
* (multiplication operator)
     for lists 59, 363
     for numbers 47
     for strings 68, 358
     for tuples 63, 365
     use of __mult__ 384
     use of __rmul__ 384
** (exponentiation operator) 352
/ (division operator) 47
[] (empty list) 53, 363
+ (addition operator) for numbers 47
+ (concatenation operator)
     for lists 59, 363
     for strings 68, 358
     for tuples 63, 365
     use of __add__ 384
     use of __radd__ 384
< (less than) 97, 352
<< (shift left operator) 352
<= (less than or equal to) 97, 352
<> (not equal to) 97, 352
= (assignment operator)
     for assigning to shelves 142, 379
     for creating/assigning to dictionaries 83
     for creating/assigning to a list 52, 363
     for creating/assigning to a string 45
     for creating/assigning to a tuple 63, 365
     for creating/assigning to a variable 44
     for instantiating a class 174, 381
== (equal to, comparison operator) 97, 352
> (greater than) 97, 352
>= (greater than or equal to) 97, 352
>> (shift right operator) 352
>>> (interactive mode prompt) 25
\ (statement continuation indicator) 96, 368
\'(single-quote character) 68
\" (double-quote character) 69
\\ (backslash character) 69
\a (bell character) 69
\b (backspace character) 69
\f (formfeed character) 69
\n (newline character) 46
\r (carriage return character) 69
\t (tab character) 46
\v (vertical tab character) 69
^ (bitwise exclusive or operator) 352
`` (backquote notation) 78, 359
{} (empty dictionary) 83
~ (bitwise negation operator) 352
__abs__ (special method attribute) 385
__add__ (special method attribute) 229, 384
__and__ (special method attribute) 384
__bases__ (base classes of an object) 222
__builtin__ (built-in module) 114
__builtins__ 115
__call__ (special method attribute) 383
__class__ (obtain the class of an instance) 178, 222
__cmp__ (special method attribute) 383
__coerce__ (special method attribute) 385
__del__ (class instance destructor) 189, 382
__delattr__ (special method attribute) 383
__delitem__ (special method attribute) 231, 383
__delslice__ (special method attribute) 231, 384
__div__ (special method attribute) 384
__divmod__ (special method attribute) 384
__doc__ (documentation string)
     for built-in functions 118
     for classes and methods 381
     for classes and methodsobjectDoc 180
     for functions 100, 369
     for modules 371
__float__ (special method attribute) 385
__getattr__ (special method attribute) 383
__getitem__ (special method attribute) 229, 383
__getslice__ (special method attribute) 229, 384
__hash__ (special method attribute) 383
__hex__ (special method attribute) 385
__init__ (constructors for class instances) 174, 381, 382
__int__ (special method attribute) 385
__invert__ (special method attribute) 385
__len__ (special method attribute) 231, 383
__long__ (special method attribute) 385
__lshift__ (special method attribute) 384
__main__ (script or interactive session name) 115
__mod__ (special method attribute) 384
__mul__ (special method attribute) 231, 384
__name__ 115
__name__ (finding the class name of an object) 222
__neg__ (special method attribute) 385
__nonzero__ (special method attribute) 385
__oct__ (special method attribute) 385
__or__ (special method attribute) 384
__pos__ (special method attribute) 385
__pow__ (special method attribute) 384
__radd__ (special method attribute) 384
__repr__ (special method attribute) 382
__rmul__ (special method attribute) 384
__rshift__ (special method attribute) 384
__rsub__ (special method attribute) 384
__setattr__ (special method attribute) 383
__setitem__ (special method attribute) 229, 383
__setslice__ (special method attribute) 229, 384
__str__ (special method attribute) 225, 382
__sub__ (special method attribute) 384
__xor__ (special method attribute) 384
 
A
 
abs (absolute value) 355
absolute pathnames 121
     in UNIX 121
     in Windows 95/98/NT 121
Access
     guidelines for using a Python client with 264
     Python fetching data from 262
     Python updating a record of 262
addition operator (+), for numbers 47
Amiga, Python support on 22
and (logical operator) 97, 352
anonymous functions (lambda) 100
append (list method) 54, 364
apply (call a function) 392
arguments. See command line or function(s)
arithmetic operators (+, -, *, /, **, %) 352
ArithmeticError (exception) 387
array module 51
array(s)
     read values from a file into (fromfile) 377
     write values to a file from (tofile) 377
assert statement (debug statement) 152, 223, 386
AssertionError (exception) 387
assignment operator (=)
     for assigning to shelves 142, 379
     for creating/assigning to a dictionary 83
     for creating/assigning to a list 52, 363
     for creating/assigning to a string 45
     for creating/assigning to a tuple 63, 365
     for creating/assigning to a variable 44
     for instantiating a class 174, 381
associative arrays. See dictionaries
AttributeError (exception) 387
attributes 108
 
B
 
backquote notation (` `) 78, 359
backslash character (\\) 69
backspace character (\b) 69
bell character (\a) 69
BeOS, Python support on 22
binary data
     reading from files (struct) 138
     reading to and from strings 133
     writing to files (struct) 138
binary mode
     opening files in 133
binary records (for reading and writing data) 137
binary, unbuffered input/output 164, 374
bindings (names to objects in namespaces) 114
bisect module
     bisect.bisect (sorted position in a list) 56, 365
     bisect.insort (add element to a list maintaining sorted order) 56, 364
bitwise and operator (&) 352
bitwise exclusive or operator (^) 352
bitwise negation operator (~) 352
bitwise operators (<<, >>, &, |, ^, ~) 352
bitwise or operator (|) 352
block structure 42?43, 94?96
blocks. See block structure
Bobo. See Zope
boolean expressions 96?98
booleans 96?98
bound methods 175
break (statement)
     in for loops 92, 369
     in while loops 91, 369
built-in functions
     list of 118
     obtaining documentation strings of 118
     overriding 118
built-in namespace ( __builtin__ ) 114
byte code. See code objects and .py files
bytecode (.pyc or .pyo files) 109
 
C
 
C
     comparison with Python 4, 6
C++
     comparison with Python 4, 6
C/C++
     reading data files generated by (struct) 138
     using for creating Python extensions. See extensions
     writing data files for (struct) 138
cache implementation example 89, 140
carriage return character (\b) 69
cgi module 347
CGI programming. See Zope, HTMLgen, cgi module
characters. See strings
chr (obtain character represented by an integer) 358
class (class definition statement) 174
class instance objects 175
     See also classes
classes
     bound and unbound methods 175
     class methods 179
     cleanup methods 189
     comparison rules for 353
classes (continued)
     constructors for ( __init__ ) 174, 381
     cyclical references in instances of 190
     defining and using 174
     definition template 381
     destructor methods for ( __del__ ) 189
     documentation strings for ( __doc__ ) 180, 381
     finding the base classes of an instance ( __bases__ ) 222
     inheritance, multiple 192
     instance variables 175
     instance variables, in inheritance 182
     instantiation 174, 381
     memory management of 189
     methods 381
     obtaining the class type of an instance ( __class__ ) 222
     obtaining the name of an instance ( __name__ ) 222
     private methods 184
     private variables 184
     using class variable to initialize instance variables 178
     using the class name of ( __class__ ) 178
     using to define structures 174
clear (dictionary method) 367
close
     for files 132, 376
     for shelves 142, 379
cmath module (for complex numbers) 49, 357
cmd module (command line interpreter development) 394
cmp (comparison function) 57, 355
code objects
     creation of (compile) 393
     execution (eval) 393
     execution (exec statement) 392
coerce (coerce to same type) 355
COM integration for Python 243
     calling Windows DLL?s from Python (calldll) 267
     importing the Python COM Modules 246
     installation and setup of PythonWin 246
     introduction to 243
     MFC wrappers for Python 267
     ODBC support 266
     possiblities for 244
     Python as a COM client
           fetching data from Access 262
           guidelines for use 264
           starting Excel and pushing in data 263
           starting Word and pushing in data 263
           updating an Access record 262
           using COM?s type libraries (compile time binding) 263
           writing helper functions for 264
     Python as a COM server
           callbacks to VB 257
           code body 249
           complete template 250
           distributing with Distributed COM 261
           instantiation from Visual Basic 251
           other possibilities with an Excel client 261
           passing lists to VB 254
           passing numbers to and from VB 253
           passing objects to and from VB 256
           passing strings to and from VB 254
           receiving lists from VB 254
           registering with COM 248
           sending data to Excel 259
           sending multiple dimension lists to VB 256
           sending odd shaped lists to VB 256
           sending tabular data to VB 255
           shutting down 253
           starting from Excel 259
           test code 248
           troubleshooting 252
           using with an Excel client 258
           using with Visual Basic 252
           writing methods for 248
     Python script for creating Desktop shortcuts 265
     registering Python with the Windows Scripting Host 265
     setting up a Python COM server 247
     sources of further information for 267
     Windows API wrappers 267
command line arguments
     for scripts 157
command line interpreters, developing (cmd module) 394
command line scripts. See scripts
comments (#) 44
comparison operators (<, <=, ==, >, >=, !=, <>, in, not in, is, is not) 97, 352
comparison ordering rules in 353
comparisons, compound 97
compile (create a code object) 393
complex (convert to a complex number) 357
complex numbers 49, 357
compound statements 94, 368
concatenation operator (+)
     for lists 59, 363
     for strings 68, 358
     for tuples 63, 365
continue (statement)
     in for loops 92, 369
     in while loops 91, 369
continuing statements across multiple lines 96, 368
control flow constructs in Python 90, 368
conversions between types. See type conversions
copy (dictionary copy method) 368
copy module
     copy.copy (make a shallow copy of an object) 394
     copy.deepcopy (make a deep copy of an object) 62, 394
count (list matching method) 60, 365
cPickle module
     cPickle.dump (write a Python object to a file) 138?141, 379
     cPickle.load (read a Python object from a file) 138?141, 379
current date. See time module
current time. See time module
current working directory, getting the (os.getcwd) 122, 374
cyclical references, breaking 190
 
D
 
data members. See classes, instance variables
data persistence. See pickling and shelves
data serialization. See pickling
date, current. See time module
debug statements (assert) 152, 223, 386
deep copies (copy module) 394
def (function definition statement) 99, 369
def (method definition statement) 175, 381
default values, for function parameters 101
del (deletion statement)
     deletion of dictionary entries 85, 367, 380
     deletion of list elements 55, 364
     deletion of module bindings 115
     deletion of namespace entries 115
     deletion of shelf entries 142, 379
     deletion of variables 44
     use of __delattr__ 383
     use of __delitem__ 383
     use of __delslice__ 384
development environment. See IDLE
dictionaries 34?35, 82?89
     adding entries to (=) 83, 367, 379
     adding multiple entries to (update) 86, 368
     combining the contents of two (update) 86, 368
     comparison rules for 353?354
     copying (copy) 368
     copying (copy, copy.deepcopy) 86
     copying, deep (copy.deepcopy) 394
     creating (=) 83, 367
     creating (=), with initial entries 84, 367
     deleting entries from (del) 85, 367, 380
     delimiters [] 84
     efficiency of 89
     implementing a cache with 88?89
     key membership (has_key) 85, 367
     keys/indices of (keys) 84, 367, 379
     key-value pairs in (items) 85, 367
     number of entries in (len) 84, 368
     persistent version of. See shelves
     reading from a file (cPickle.load) 138?141, 379
     removing all entries from (clear) 367
dictionaries (continued)
     representing sparse matrices with 88
     retrieving values from (get) 86, 367
     subclassing (UserDict module) 395
     tuples as keys for 87
     valid keys for 87
     values in (values) 85, 367
     writing to a file (cPickle.dump) 138?141, 379
dir (display attributes of an object) 393
dir (display names in a module) 117, 220
directories
     changing (os.chdir) 123, 380
     copying recursively (shutil.copytree) 381
     creating (os.mkdir, os.makedirs) 129, 380
     deleting (os.rmdir) 129, 380
     getting the current working directory (os.getcwd) 122, 374
     listing the files in (os.listdir) 123, 128, 380
     obtaining from a pathname (os.path.basename) 125, 374
     obtaining the access time of (os.path.getatime) 375
     obtaining the modification time of (os.path.getmtime) 375
     obtaining the name of (os.path.dirname) 125, 374
     processing files in a directory tree (os.path.walk) 129?130, 380
     renaming (os.rename) 128, 380
     testing the existence of (os.path.isdir) 127, 375
distributing Python programs 171
division operator (/), for numbers 47
divmod (find quotient and remainder) 355
DLLs
     calling from Python (calldll) 267
documentation string ( __doc__ )
     for built-in functions 118
     for classes and methods 179?180, 381
     for functions 100, 369
     for modules 371
DOS, Python support on 22
double-quote character (") 69
 
E
 
elif (statement)
     with if-else constructs 91, 369
else (statement)
     with exceptions 150, 385
     with for loops 92, 369
     with if-else constructs 91, 369
     with while loops 91, 369
empty value. See None
endian, converting when reading and writing data 138
environment variables (os.environ) 126, 380
environment variables, summary 373
EnvironmentError (exception) 387
EOFError (exception) 387
equal to (==), comparison operator 97, 352
equality tests
     based on identity (is, is not) 98
     based on value (==, !=, <>) 98
errors. See exceptions
escape sequences
     basic (\', ", \\, \a, \b, \f, \n, \r, \t, \v) 69, 357
     hexadecimal character representation (\xFF) 70, 357
     octal character representation (\777) 70, 357
eval (evaluate an expression or code object) 393
Excel
     guidelines for using a Python client with 264
     possibilities for as a client for a Python COM server 261
     retrieving data from a Python COM server 259
     setting up a workbook with a server 259
     started by a Python client and receiving data 263
     starting a Python COM server from 259
     using as a client for a Python COM server 258
except (statement) 150, 385
Exception (parent of all exceptions) 387
exception types
     ArithmeticError 387
     AssertionError 387
     AttributeError 387
     EnvironmentError 387
     EOFError 387
     Exception 387
     FloatingPointError 387
     ImportError 387
     IndexError 387
     IOError 387
     KeyboardError 387
     KeyError 387
     LookupError 387
     MemoryError 387
     NameError 387
     NotImplementedError 387
     OSError 387
     OverflowError 387
     RuntimeError 387
     StandardError 387
     SyntaxError 388
     SystemError 388
     SystemExit 388
     TypeError 388
     ValueError 388
     ZeroDivisionError 388
exceptions 144?155, 385?388
     assert statements 152
     catching and handling (try-except-else) 150, 385
     defining new types of 151
     hierarchy of in Python 148, 386
     inheritance hierarchy, effect on catching of 153
     raising (raise) 149, 386
     summary of 386
     types of in Python 148, 386
     where to use 155
exec statement (execute Python code) 392
executables
     creating as UNIX scripts 161
     creating with the freeze tool 171
execute a system command (os.system) 394
exit the interpreter (sys.exit) 395
exiting the interactive mode 25
exponentiation operator (**) 352
expression(s) 45
     boolean 97?98
     in program evaluation of (eval) 393
extend (list method) 364
extensions (in C/C++) 269?278
     compilation support for (in UNIX) 271
     compilation support for (in Windows) 271
     compiler choice 270
     example 271?275
     incrementing and decrementing reference counts 276?277
     memory management, example 276?277
     memory management, issues in 275
     shared versus static extensions 270
     template for 274
     using C++ 278
 
F
 
false Boolean values 97
file object(s) 131
file object(s). See also file(s)
file(s)
     closing (close) 132, 376
     copying (shutil.copyfile, shutil.copy, shutil.copy2) 381
     copying all of in a directory tree (shutil.copytree) 381
     copying mode permissions information of (shutil.copymode) 381
     copying stat information of (shutil.copystat) 381
     deleting (os.remove) 129, 380
     determine current position in (tell) 378
     execute as code (exec statement) 392
     expansion of names of (glob.glob) 128, 165, 376
     force buffered output to be written to (flush) 378
     move within (seek) 378
     obtaining from a pathname (os.path.basename) 125, 374
     obtaining the access time of (os.path.getatime) 375
     obtaining the extension of (os.path.splitext) 125, 374
file(s) (continued)
     obtaining the modification time of (os.path.getmtime) 375
     obtaining the size of (os.path.getsize) 375
     opening (open) 131, 132, 133
     opening in binary mode 133
     processing files in a directory tree (os.path.walk) 129?130, 380
     read values into an array from (fromfile) 377
     reading a binary record from (read) 137, 379
     reading a fixed amount from (read) 133, 376
     reading a line of (readline) 132, 133, 376
     reading a Python object from (cPickle.load) 138?141, 379
     reading all lines of (readlines) 133, 376
     reading all of into a string (read) 133, 376
     reading binary data from (read) 133
     reading binary data from (struct) 138
     reading lines from a set of (fileinput module) 378
     renaming (os.rename) 128, 380
     standard input, standard output, and standard error 135, 377
     testing the existence of (os.path.isfile) 127, 375
     write values from an array to (tofile) 377
     writing a list of strings to (writelines) 134, 377
     writing a Python object to (cPickle.dump) 138?141, 379
     writing a string to (write) 134, 376
     writing binary data to (struct) 138
     writing binary data to (write) 134
filehandles. See file object(s)
fileinput module 160?161, 378
     fileinput.close (close the stream) 161, 378
     fileinput.filelineno (lines read in from current file) 161, 378
     fileinput.filename (name of current file being read) 161, 378
     fileinput.input (iterate over lines of input files) 378
     fileinput.input (iterate over lines of input files) fileinput 160
     fileinput.isfirstline (reading first line of file) 161, 378
     fileinput.isstdin (reading standard input) 161, 378
     fileinput.lineno (total lines read in) 161, 378
     fileinput.nextfile (skip to the next input file) 161, 378
filesystem(s) 120?130
     See also pathnames, files, directories
filter (built-in function) 393
finalizers (try-finally statements) 191, 386
finally statement 191, 386
findall ( find all occurrences of a regular expression in a string) 388
float (conversion function)
     for converting a long integer to a floating point number 47, 355
     for converting a string to a floating point number 73, 360
     for converting an integer to a floating point number 47, 355
floating point numbers. See floats
FloatingPointError (exception) 387
floats (floating point numbers) 46, 354
flush (force buffered output to be written to a file) 378
for loops 92, 93, 227, 369
     syntax for 92
     use of __getitem__ 227
     use with the range function 92
     with tuple unpacking 93
formal string representation (repr) 78
format string
     as a template for a binary record (struct) 137
formatting sequences with named parameters 360
formfeed character (\b) 69
freeze tool (create Python binaries) 171
Friedrich, Robin xxi
fromfile (read values into an array) 377
ftplib module (FTP protocol interface) 347
function(s) 99?105, 369?371
     anonymous (lambda) 100
     arguments, passing by parameter name 102, 370
     assigning to a variable 100
     built-in. See built-in functions
     calling generically (apply) 392
     definition of (def) 99, 369
     documentation string of ( __doc__ ) 100, 369
     global variables in 105
     local variables in 104
     parameters, default values 101, 370
     parameters, indefinite number of - by keyword 103, 370
     parameters, indefinite number of - by position 103, 370
     parameters, keyword 102, 370
     return value of (return) 99, 370
     using operators as (operators module) 394
 
G
 
garbage collection 189
get (dictionary value retrieval method) 85, 367
getopt module (parse command line arguments) 159, 394
glob module
     glob.glob (pathname pattern expansion) 128, 165, 376
global namespace 114
globals (obtain the global namespace) 115, 393
greater than (>) 97, 352
greater than or equal to (>=) 97, 352
group (obtain regular expression matches from a string) 238, 389
groupdict (named groups in a match object) 389
GUI development. See also Tk
GUI libraries for Python
     Gtk (GNU Toolkit) 206
     Qt Package (of the KDE) 206
     Tk 194?206
 
H
 
has_key (key existence method)
     for dictionaries 85, 367
     for shelves 142, 379
hashtables. See dictionaries
help line, Python?s (python-help@python.org) 20
hex (convert an integer to a hexadecimal string representation) 356
hexadecimal character representation (\xFF) 70, 357
hexadecimal integers (0xFFFF) 354
home web page, Python?s (www.python.org) 19
HTML page generation. See Zope and HTMLgen
HTML parsing (htmllib module) 347
HTMLgen (web page generation package) 297?320
     BarChart (class) 320
     barchart module for (barchart.py) 320
     BasicDocument (class) 304
     BulletList (class) 308
     calendar creation with (HTMLcalendar.py) 320
     CGI and Forms support in 316?319
     color module for (HTMLcolors.py) 319
     creating anchor tags with (Href) 312
     creating frames in 309
     creating image maps with (Map) 311
     CSS1 (Cascading Style Sheet) support 313?315
     defining lists with (List) 308
     DefinitionList (class) 309
     document hierarchy of 304
     example - Quick Start 298
     FrameSet (object) 309
     FramesetDocument (class) 305, 309
     future plans of 320
     high speed object creation (using __call__ ) 313
     Href (class) 312
     Image (class) 310
     ImageBulletList (class) 309
HTMLgen (continued)
     List (class) 308
     Map (object) 311
     NonBulletList (class) 309
     NumberedList (class) 308
     object rendering by 304
     OrderedList (class) 308
     persistence of Forms (StickyForm) 319
     placing images in (Image) 310
     resource file example 301
     resource files for 299
     samples (HTMLtest.py) 319
     SeriesDocument (class) 299, 305
     Simple Document (class) 299
     StickyForm (class) 319
     subclassing an existing Document class of 305
     Table (class) 306
     table generation in (Table, TableLite) 306
     TableLite (class) 306
     when to use 298
     where to obtain 298
htmllib module (parse html) 347
HTTP programming. See Zope, httplib
httplib module 347
 
I
 
IDLE (Integrated Development Environment)
     for creating/editing a module 107
     introduction to 24
     problems starting 24
     starting 24
     using the Python Shell window 25
if-elif-else statements 91, 369
image processing and displaying (PIL) 346
imaginary numbers. See complex numbers
immutability (non-modifiability)
     of numbers 87
     of strings 68
     of tuples 63
import (bring in from a module) 110, 371
ImportError (exception) 110, 387
in (membership operator) 97
     for lists 58, 365
     for strings 77
     for tuples 63, 366
     summary 352
indentation 42?43, 94?96
index (list search method) 60, 365
index notation
     for lists 52, 363
     for strings 67, 358
     for tuples 63, 366
     See also slice notation
     use of __getitem__ 227
IndexError (exception) 387
informal string representation (str) 79
inheritance, multiple 192?193
input (prompt for and read in a Python expression) 134, 377
input/output. See file(s)
insert (list insertion method) 55, 364
installing Python
     on Macintosh 22
     on UNIX (including Linux) 22
     on Windows 95/98/NT 22
instance variables 175
int (conversion function)
     for converting a float to an integer 47, 356
     for converting a long integer to an integer 47, 356
     for converting a string to an integer 73, 360
integers 46, 354
integers (hexadecimal) 354
integers (maximum allowed value of sys.maxint) 354
integers (octal) 354
integrated development environment. See IDLE
interactive mode 396
     command prompt in (>>>) 25
     exiting a session 25
     for UNIX 23
     for UNIX, command history 396
     for UNIX, command line editing 396
     for UNIX, key bindings 396
     for Windows 95/98 23
     for Windows 95/98, keybindings 396
     starting a session 22
     Windows 95/98, copy and paste 396
     Windows 95/98, fixing paste problem 396
interpreter development, command line (cmd module) 394
IOError (exception) 387
is (identity operator) 98, 352
is not (identity operator) 98, 352
isinstance (built-in function) 222, 393
issubclass (built-in function) 223, 393
items (dictionary contents method) 85, 367
iteration. See for loops, while loops
 
J
 
Java
     comparison with Python 4, 6
     difference in memory management for 190
     integration of Python with (JPython)
           279
JPython 280?296
     __builtin__ class 291
     calling compiled Python code from Java 291
     compiling to Java bytecode (jpythonc) 293
     development approaches when using with Java 295
     downloading and installing 283
     example applet ('Hello World') 281
     example java class (general ledger) 286
     example java class extension (general ledger) 287
     extending (subclassing) Java classes in 287
     Java Bean property mappings 286
     Java proxy classes 285
     jpythonc (compile to java byte code) 293
     Py.java2py method 290
     PyDictionary class 289
     PyList class 290
     PyLong class 290
     PyObject class 290
     PySequence class 290
     PyString class 290
     Python Server Pages (PSP) 296
     PythonInterpreter class 289
     PyTuple class 290
     speed of 281
     using from within Java (PythonInterpreter) 289
     using java classes from within 285
     using special method attributes (PyObject) 290
     using to test java classes 287
 
K
 
KeyboardError (exception) 387
KeyError (exception) 387
keys (dictionary indices) 84, 367, 379
keyword arguments 370
keyword arguments (for functions) 102
keywords in Python 351
 
L
 
lambda expressions 100, 370
Latteier, Amos xxi
legal restrictions on use, lack thereof 12
len (length function)
     for dictionaries 84, 368
     for lists 52, 365
     for shelves 142, 379
     for strings 68, 358
     for tuples 63, 366
     use in for loops with the range function 92
     use of __len__ 383
less than (<) 97, 352
less than or equal to (<=) 97, 352
library modules 113
lines, splitting statements across 96, 368
links, testing for (os.path.islink) 128, 375
Linux, installing Python on 22
list (conversion function)
     for converting a string to a list 66, 77, 363
     for converting a tuple to a list 66, 363
list(s) 52?62, 364?365
     appending an element to (append) 54, 364
     bulk initialization of (*) 59, 363
     comparison rules for 353
     concatenation (+) 59, 363
     copying 54, 62
list(s) (continued)
     copying, deep (copy.deepcopy) 394
     copying, shallow versus deep 62
     creating (=) 52, 363
     creating with the range function 93, 393
     delimiters [] 52, 364
     element deletion, by position (del) 55, 364
     element deletion, by value (remove) 55, 364
     empty [] 64
     extending a list (extend) 364
     finding sorted position in (bisect.bisect) 56, 365
     finding the maximum value of (max) 59, 365
     finding the minimum value of (min) 59, 365
     index notation 52?54, 363
     inserting an element in sorted order (bisect.insort) 56, 365
     inserting an element into (insert) 55, 364
     length (len) 52, 365
     making an object behave like one (special method attributes) 228
     matches in (count) 60, 365
     membership determination (in) 58, 365
     modification of 54
     multidimensional 60, 363
     multiplication operator (*) 59, 363
     nested 60, 363
     packing and unpacking 65
     pop an element out of (pop) 364
     reading from a file (cPickle.load) 138?141, 379
     representing matrices with 60
     reversal of (reverse) 56, 364
     searching in (index) 60, 365
     slice notation for 53, 363
     sorted order, insert element in (bisect.inorder) 56, 365
     sorted, partitioning (bisect.bisect) 56
     sorting (sort) 56, 364
     sorting with a custom ordering function 57?58, 365
     subclassing (UserList module) 395
     writing to a file (cPickle.dump) 138?141, 379
Lloyd, Brian xxi
local namespace 114
locals (obtain the local namespace) 115, 393
logical operators (and, or, not) 97, 352
long (conversion function)
     for converting a float to a long integer 47, 356
     for converting a string to a long integer 73, 360
     for converting an integer to a long integer 47, 356
long integers (unlimited precision) 46, 354
LookupError (exception) 387
loops. See for loops, while loops
 
M
 
Macintosh, installing Python on 22
map (built-in function) 393
map objects. See dictionaries
match (determine if a string matches a regular expression) 389
match objects (regular expression match)
     obtaining a named group from (group) 389
     obtaining the named groups in (groupdict) 389
math module 48
     math.acos (arc cosine) 355
     math.asin (arc sine) 355
     math.atan (arc tangent) 355
     math.atan2 (arc tangent) 355
     math.ceil (ceiling) 355
     math.cos (cosine) 355
     math.cosh (hyperbolic cosine) 355
     math.e (e constant) 355
     math.exp (value raised to e) 355
     math.fabs (absolute value of a float) 355
     math.floor (floor) 355
     math.fmod (modulus of floats) 356
     math.hypot (hypotenuse) 356
     math.log (log base e) 356
     math.log10 (log base 10) 356
     math.modf (modulus of a fraction) 356
     math.pi (pi constant) 356
     math.sin (hyperbolic sine) 356
     math.sinh (sine) 356
     math.sqrt (square root) 356
     math.tan (tangent) 357
     math.tanh (hyperbolic tangent) 357
matrix
     representation using lists 60
     sparse matrix representation with dictionaries 88
max (maximum function)
     for lists 59, 365
     for tuples 63, 366
memory management 189
MemoryError (exception) 387
MFC wrappers for Python 267
Microsoft Access. See Access
Microsoft Excel. See Excel
Microsoft Windows. See Windows
Microsoft Word. See Word
min (minimum function)
     for lists 59, 365
     for tuples 63, 366
minus operator (-), unary 352
module(s) 106?114, 167?171, 371
     combining with scripts 167
     definition template 371
     documentation string of ( __doc__) 371
     importing from (import) 110, 371
     library modules 113
     private names in 112
     regression testing with scripts 170
     reloading (reload) 109, 372
     search path for (sys.path) 110, 372
     third-party modules 114
     where to place them 111
modulus operator (%)
     for numbers 352
     for strings 76?81, 360?361
mount points, testing for (os.path.ismount) 128, 375
MS-DOS Prompt Window
     executing a command on from Python (os.system) 394
     starting a script from 164
multiline statements 96, 368
multiple inheritance 192?193
multiplication operator (*)
     for lists 59, 363
     for numbers 47
     for strings 358
     for tuples 63, 365
multithreaded programming, Java-like (threading module) 347
multithreaded programming, low-level (thread module) 347
 
N
 
NameError (exception) 387
namespaces 114?119
     bindings in 114
     built-in namespace ( __builtin__ ) 114
     class namespace (self) 185
     displaying the built-in namespace (dir) 117
     for functions in interactive sessions 116
     for functions in modules 117
     for interactive sessions 114, 115
     for modules 117
     for scripts 114
     global namespace 114
     instance namespace (self) 185
     local namespace 114
     obtaining the global namespace (globals) 115, 393
     obtaining the local namespace (locals) 115, 393
     overriding built-in functions 118
     superclass namespace (self) 185
newline character (\n) 46
newsgroup, Python?s (comp.lang.python) 19
nil value. See None
nntplib module (internet news interface) 347
None 50
not (logical operator) 97, 352
not equal to (!=, <>) 97, 352
not in (membership operator) 97, 352
NotImplementedError (exception) 387
number(s) 46?49, 355?357
     addition operator (+) 47
number(s) (continued)
     coerce to same type (coerce) 355
     compare (cmp) 355
     comparison rules for 353?354
     complex numbers 49, 354, 357
     division operator (/) 47
     find absolute value (abs) 355
     find absolute value of a float (math.fabs) 355
     find arc cosine (math.acos) 355
     find arc sine (math.asin) 355
     find arc tangent (math.atan) 355
     find arc tangent (math.atan2) 355
     find ceiling (math.ceil) 355
     find cosine (math.cos) 355
     find e constant (math.e) 355
     find floor (math.floor) 355
     find hyperbolic cosine (math.cosh) 355
     find hyperbolic sine (math.sin) 356
     find hyperbolic tangent (math.tanh) 357
     find hypotenuse (math.hypot) 356
     find log base 10 (math.log10) 356
     find log base e (math.log) 356
     find modulus of a fraction (math.modf) 356
     find modulus of floats (math.fmod) 356
     find pi constant (math.pi) 356
     find quotient and remainder (divmod) 355
     find sine (math.sinh) 356
     find square root (math.sqrt) 356
     find tangent (math.tan) 357
     find value raised to e (math.exp) 355
     floats (floating point) 46, 354
     integers 46, 354
     long integers (unlimited precision) 46, 354
     multiplication operator (*) 47
     raise to power of (pow) 356
     round to nearest integer (round) 356
     subraction operator (-) 47
numeric computation 48
numeric functions
     built in 47
     in math module 48
NumPy (numeric computation package) 48, 346
 
O
 
object-oriented programming in Python 173?193 See also classes
objects See also classes
     making shallow or deep copies of (copy module) 394
     Python definition of 175
     reading from a file (cPickle.load) 138?141, 379?381
     writing to a file (cPickle.dump) 138?141, 379?380
oct (convert an integer to an octal string representation) 356
octal character representation (\777) 70, 357
octal integers (0777) 354
ODBC
     Python COM support for 266
open (open a file) 131, 132, 133
Open Source Software discussion 11
operating system name (os.name, sys.platform) 126
operator overloading. See special method attributes
operators
     arithmetic (+, -, *, /, **, %) 352
     bitwise (<<, >>, &, |, ^, ~) 352
     comparison (<, <=, ==, >, >=, !=, <>, in, not in, is, is not) 97, 352
     logical (and, or, not) 97, 352
     precedence 352
     summary 351
     using as functions (operators module) 394
operators module (use operators as functions) 394
or (logical operator) 97, 352
ord (obtain the integer that represents an ASCII character) 358
ordering function
     customized for sorting lists 57
os module
     os.chdir (change directory) 123, 380
     os.curdir (current directory indicator) 123, 126, 374
     os.environ (the environment variables) 126, 380
     os.getcwd (get the current working directory) 122, 374
     os.listdir (list the files in a directory) 123, 128, 380
     os.makedirs (create a directory) 129, 380
     os.mkdir (create a directory) 129, 380
     os.name (operating system name) 126, 380
     os.pardir (parent directory indicator) 126, 374
     os.path.basename (obtain the base file/directory) 125, 374
     os.path.commonprefix (find the common prefix in a set of pathnames) 125, 375
     os.path.dirname (obtain the directory name) 125, 374
     os.path.exists (test the existence of a pathname) 127, 375
     os.path.expanduser (expand the user name variable) 126
     os.path.expandvars (expand the system variables) 126, 375
     os.path.getatime (obtain the access time of a file or directory) 375
     os.path.getmtime (obtain the modification time of a file or directory) 375
     os.path.getsize (obtain the size of a file) 375
     os.path.isabs (test for an absolute pathname) 128, 375
     os.path.isdir (test for a directory) 127, 375
     os.path.isfile (test for a file) 127, 375
     os.path.islink (test for a link) 128, 375
     os.path.ismount (test for a mount point) 128, 375
     os.path.join (creating pathnames) 123?125, 374
     os.path.normcase (normalize the case of a pathname) 375
     os.path.normpath (normalize a pathname) 375
     os.path.samefile (test if two pathnames are the same file) 128, 375
     os.path.split (splitting pathnames) 125, 374
     os.path.splitdrive (split the drive out of a pathname) 376
     os.path.splitext (obtain the file extension) 125, 374
     os.path.walk (process files in a directory tree) 129?130, 380
     os.remove (delete a file) 129, 380
     os.rename (rename a file or directory) 128, 380
     os.rmdir (delete a directory) 129, 380
     os.system (execute system command) 394
OS/2, Python support on 22
OSError (exception) 387
output. See file(s)
OverflowError (exception) 387
 
P
 
.py files (Python source code files) 108, 115
.pyc files (compiled bytecode files) 109
.pyo files (optimized compiled bytecode files) 373
packages
     __all__ attribute of 216
     __init__.py file in 216
     basic use of 211
     defining and initializing (__init__.py) 216
     example use 213
     loading subpackages and submodules of 214
     proper use of 218
packing
     binary data (struct.pack) 138, 379
     lists 65
     tuples 65
     use of __getitem__ 230
parameters. See function(s), parameters
pass (statement) 91, 368
pathname(s)
     absolute 121
     creating (os.path.join) 124?125, 374
     expand the system variables of (os.path.expandvars) 126, 375
     expand the user name variable of (os.path.expanduser) 126
     expansion of (glob.glob) 128, 165, 376
pathname(s) (continued)
     normalize (os.path.normpath) 375
     normalizing the case of (os.path.normcase) 375
     obtaining common prefix of a set of (os.path.commonprefix) 125, 375
     obtaining the base of (os.path.basename) 125, 374
     obtaining the directory of (os.path.dirname) 125, 374
     obtaining the file extension of (os.path.splitext) 125, 374
     relative 121
     split the drive out of (os.path.splitdrive) 376
     splitting (os.path.split) 125, 374
     test if it is absolute (os.path.isabs) 128, 375
     testing for a directory (os.path.isdir) 127, 375
     testing for a file (os.path.isfile) 127, 375
     testing the existence of (os.path.exists) 127, 375
paths. See pathname(s)
pattern matching. See regular expressions
Perl, comparison with Python 4, 9
persistent data. See pickling and shelves
pickling (reading and writing Python objects from files) 138?141, 379
pictures and images. See PIL
PIL (Python Imaging Library) 346
piping I/O between commands | 158
placeholder value. See None
platform specific test (os.name, sys.platform) 126
Pmw (Python Megawidgets), Tkinter extensions 205
pop (list element removal method) 364
pow (raise to power) 356
print statement 70, 377
printing
     any Python object (using repr , str or ` `)objectToString 79
     escape sequences 70?72
     formatted strings with the modulus operator (%) 79?81
     formatting sequences with named parameters 81
     special formatting characters for (escape sequences) 69
     to standard out 135
     using a comma to avoid a newline being added 70
private variables/methods of classes 184
procedure(s) 100
programs. See scripts
prompting for an input expression (input) 134, 377
prompting for text input (raw_input) 134, 377
PSA (Python Software Association) 12
.pth files (additions to sys.path) 112
.pyc files (compiled bytecode files) 109
Python
     comparison with C 4, 6?7
     comparison with C++ 4, 6?7
     comparison with Java 4, 6?7
     comparison with Perl 4, 9?10
     comparison with Tcl/Tk 4, 8?9
     comparison with Visual Basic 4, 7?8
Python Help line (python-help@python.org) 20
Python Internet news group (comp.lang.python) 19
Python interpreter summary 372
Python keywords 351
Python Language Reference 19
Python Library Reference 19
Python Shell window of IDLE, using 25
Python SIGs (significant interest groups) 20
Python?s home web page (www.python.org) 19
PYTHONINSPECT (environment variable) 373
PYTHONOPTIMIZE (environment variable) 373
PYTHONPATH (module search path variable) 110, 373
PYTHONSTARTUP (startup file indicator) 373
PYTHONUNBUFFERED (binary unbuffered IO) 164, 374
PYTHONVERBOSE (environment variable) 374
PythonWin. See COM integration for Python
 
Q
 
QNX, Python support on 22
qualification 108
Quick Python
     appendix, format conventions used in 350
     chapter summaries 17?19
     important point markers in 14
     interactive examples in, formatting of 15
     non-interactive examples in, formatting of 16
     organization of 13
     sending feedback on 20
quitting the interpreter (sys.exit) 395
 
R
 
raise (statement) 149, 386
random integer generation (whrandom.randint) 395
random number between 0.0 and 1.0 (whrandom.random) 395
randomly choose an element out of a list (whrandom.choice) 395
range (create a list sequence) 93, 393
raw strings (r" ") 234, 357
raw_input (prompt for and read in a string) 134, 377
re module (regular expressions)
     re.compile (create and compile a regular expression) 233, 388
read
     a binary record from a file 137, 379
     a fixed amount from a file 133, 376
     read the rest of a file into a string 376
reading
     an expression from the screen (input) 134, 377
     text from the screen (raw_input) 134, 377
readline
     read a line from a file 132, 376
     read a string from a file 133, 376
     read all lines of a file 133, 376
redirecting input and output 135
reduce (built-in function) 393
reference counting 189
regular expressions 232?240, 388?392
     creating and compiling (re.compile) 233
     determine if a string matches (match) 389
     extracting matched text with 236
     extracting text from a string with (?P) 237, 391
     find all occurrences of in a string (findall) 388
     grouping ( ) 233, 391
     lookahead assertion (?= ) 391
     match a digit \d 236, 392
     match a newline \n 392
     match a non-alphanumeric \W 392
     match a tab \t 392
     match an alphanumeric \w 392
     match any character 390
     match beginning/end of a word \b 392
     match end of string or line $ 390
     match m to n repetitions {m,n} 390
     match non-digit \D 392
     match non-whitespace character \S 392
     match one or more times + 236, 390
     match optional ? 236, 390
     match same as 'name' (?P=name) 391
     match start of string or line ^ 390
     match whitespace character \s 392
     match zero or more times 390
     negative lookahead assertion (?! ) 391
     obtaining matches of from a string (group) 238, 389
     or | 233, 391
     search a string for a match (search) 233, 237, 238, 389
     split a string on (split) 389
     splitting into sections 237
     substituting text in strings with (sub) 238, 389
     summary 388
     use of raw strings for 234
relative pathnames 121
     in UNIX 121
     in Windows 95/98/NT 121
reload (reload a module) 109, 372
remove (list value removal method) 55, 364
repr (convert an object to a string) 77?79, 359
reserved words in Python 351
return (return statement of a function) 99, 370
reverse (list reversal method) 56, 364
Robinson, Andy xxii See also chapter 22
round (round to nearest integer) 356
RuntimeError (exception) 387
 
S
 
scientific computing in Python (NumPy) 346
scientific notation 46
scoping rules for Python 114?119, 185?188
     See also namespaces
scripts 157?171, 372
     combining with modules 167
     command line arguments for 157, 372
     execution options on Windows 161
     making them executable on UNIX 161
     parsing command line arguments of (getopt) 159, 394
     purpose of controlling functions in 170
     redirection of input and output for 158, 372
     setting up and starting in Windows as a Shortcut 162
     starting from a command line 157
     starting from an MS-DOS Prompt Window 164
     starting from the Windows Run box 163
     starting in Windows as a document 162
     starting in Windows by 'opening' (double click) 162
     use for module regression testing 170
search (search a string for a regular expression match) 233, 237, 238, 389
seek (move within a file) 378
self (as first argument of methods) 174, 381
sequence creation (range) 93, 393
sequence object types
     immutable. See string(s) and tuple(s)
  &nb