Python Cookbook

Front Cover
Alex Martelli, David Ascher
"O'Reilly Media, Inc.", 2002 - Computers - 574 pages

ThePython Cookbookis a collection of problems, solutions, and practical examples for Python programmers, written by Python programmers. Over the past year, members of the Python community have contributed material to an online repository of Python recipes hosted by ActiveState. This book contains the best of those recipes, accompanied by overviews and background material by key Python figures.

The recipes in thePython Cookbookrange from simple tasks, such as working with dictionaries and list comprehensions, to entire modules that demonstrate templating systems and network monitoring. This book contains over 200 recipes on the following topics:

  • Searching and sorting
  • Manipulating text
  • Working with files and the filesystem
  • Object-oriented programming
  • Dealing with threads and processes
  • System administration
  • Interacting with databases
  • Creating user interfaces
  • Network and web programming
  • Processing XML
  • Distributed programming
  • Debugging and testing
  • Extending Python

This book is a treasure trove of useful code for all Python programmers, from novices to advanced practitioners, with contributions from such Python luminaries as Guido Van Rossum, David Ascher, Tim Peters, Paul Prescod, Mark Hammond, and Alex Martelli, as well as over 100 other Python programmers. The recipes highlight Python best practices and can be used directly in day-to-day programming tasks, as a source of ideas, or as a way to learn more about Python.

The recipes in thePython Cookbookwere edited by David Ascher, who is on the board of the Python Software Foundation and is the co-author ofLearning Python,and Alex Martelli, who is known for his numerous and exhaustive postings on the Python mailing list. The book contains a foreword by Guido van Rossum, the creator of Python.

 

Contents

I
v
II
xiii
III
xvii
IV
1
V
3
VI
4
VII
6
VIII
7
CXXXVIII
260
CXXXIX
262
CXL
264
CXLI
267
CXLII
269
CXLIII
272
CXLIV
275
CXLV
276

IX
8
X
11
XI
13
XII
15
XIII
18
XIV
20
XV
21
XVI
23
XVII
25
XVIII
27
XIX
28
XX
30
XXI
31
XXII
34
XXIII
38
XXIV
40
XXV
42
XXVI
43
XXVII
46
XXVIII
47
XXIX
49
XXX
52
XXXI
54
XXXII
57
XXXIII
59
XXXIV
61
XXXV
63
XXXVI
69
XXXVII
70
XXXVIII
71
XL
72
XLI
74
XLII
76
XLIII
78
XLIV
79
XLV
81
XLVI
83
XLVII
85
XLVIII
86
XLIX
88
L
91
LI
93
LII
94
LIII
96
LIV
97
LV
99
LVI
100
LVIII
104
LIX
109
LX
113
LXI
117
LXII
119
LXIV
121
LXV
122
LXVI
123
LXVII
125
LXVIII
127
LXIX
129
LXX
132
LXXI
134
LXXII
135
LXXIII
137
LXXV
138
LXXVI
140
LXXVII
141
LXXVIII
143
LXXIX
144
LXXX
145
LXXXI
146
LXXXII
147
LXXXIII
148
LXXXIV
150
LXXXV
152
LXXXVI
154
LXXXVII
156
LXXXVIII
160
LXXXIX
165
XC
167
XCI
169
XCIII
172
XCIV
174
XCV
176
XCVI
177
XCVII
179
XCVIII
182
XCIX
183
C
186
CI
188
CII
189
CIII
191
CIV
193
CV
194
CVI
198
CVII
201
CVIII
202
CIX
203
CX
206
CXI
208
CXII
211
CXIII
214
CXIV
217
CXV
218
CXVI
220
CXVII
222
CXVIII
225
CXIX
227
CXX
229
CXXI
231
CXXII
233
CXXIII
236
CXXIV
237
CXXV
238
CXXVI
240
CXXVII
242
CXXVIII
243
CXXIX
245
CXXX
246
CXXXI
248
CXXXII
250
CXXXIII
253
CXXXIV
254
CXXXV
255
CXXXVI
257
CXXXVII
258
CXLVI
278
CXLVII
279
CXLVIII
281
CXLIX
283
CL
285
CLI
288
CLII
291
CLIII
298
CLV
300
CLVI
301
CLVII
303
CLVIII
304
CLIX
307
CLX
308
CLXI
311
CLXII
313
CLXIII
315
CLXIV
317
CLXV
318
CLXVI
322
CLXVII
326
CLXVIII
328
CLXIX
330
CLXX
331
CLXXI
333
CLXXII
334
CLXXIII
336
CLXXIV
337
CLXXV
338
CLXXVI
340
CLXXVII
342
CLXXVIII
344
CLXXIX
346
CLXXX
350
CLXXXI
353
CLXXXII
356
CLXXXIV
357
CLXXXV
359
CLXXXVI
361
CLXXXVII
362
CLXXXVIII
364
CLXXXIX
366
CXC
368
CXCI
369
CXCII
372
CXCIII
374
CXCIV
377
CXCVI
379
CXCVII
380
CXCVIII
382
CXCIX
383
CC
384
CCI
385
CCII
387
CCIII
389
CCIV
390
CCV
393
CCVI
395
CCVII
398
CCVIII
402
CCX
404
CCXI
405
CCXII
407
CCXIII
409
CCXIV
412
CCXV
414
CCXVI
417
CCXVII
420
CCXVIII
423
CCXX
424
CCXXI
425
CCXXII
428
CCXXIII
429
CCXXIV
432
CCXXV
434
CCXXVI
437
CCXXVII
440
CCXXVIII
444
CCXXX
449
CCXXXI
452
CCXXXII
454
CCXXXIII
455
CCXXXIV
457
CCXXXV
460
CCXXXVI
461
CCXXXVII
463
CCXXXVIII
465
CCXXXIX
467
CCXL
469
CCXLI
471
CCXLII
475
CCXLIV
477
CCXLV
481
CCXLVI
485
CCXLVII
488
CCXLVIII
489
CCXLIX
491
CCL
494
CCLI
496
CCLII
497
CCLIII
499
CCLIV
503
CCLV
506
CCLVI
507
CCLVII
509
CCLVIII
513
CCLIX
515
CCLX
517
CCLXI
519
CCLXII
521
CCLXIII
522
CCLXIV
524
CCLXV
526
CCLXVI
529
CCLXVII
530
CCLXVIII
532
CCLXIX
533
CCLXX
535
CCLXXI
536
CCLXXII
539
CCLXXIII
547
CCLXXIV
551
Copyright

Common terms and phrases

About the author (2002)

Alex Martelli spent 8 years with IBM Research, winning three Outstanding Technical Achievement Awards. He then spent 13 as a Senior Software Consultant at think3 inc, developing libraries, network protocols, GUI engines, event frameworks, and web access frontends. He has also taught programming languages, development methods, and numerical computing at Ferrara University and other venues. He's a C++ MVP for Brainbench, and a member of the Python Software Foundation. He currently works for AB Strakt, a Python-centered software house in G teborg, Sweden, mostly by telecommuting from his home in Bologna, Italy. Alex's proudest achievement is the articles that appeared in Bridge World (January/February 2000), which were hailed as giant steps towards solving issues that had haunted contract bridge theoreticians for decades. David Ascher is the lead for Python projects at ActiveState, including Komodo, ActiveState's integrated development environment written mostly in Python. David has taught courses about Python to corporations, in universities, and at conferences. He also organized the Python track at the 1999 and 2000 O'Reilly Open Source Conventions, and was the program chair for the 10th International Python Conference. In addition, he co-wrote Learning Python (both editions) and serves as a director of the Python Software Foundation. David holds a B.S. in physics and a Ph.D. in cognitive science, both from Brown University.

Bibliographic information