Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Beginning Python - From Novice To Professional (2005)

.pdf
Скачиваний:
139
Добавлен:
17.08.2013
Размер:
13.91 Mб
Скачать

600 I N D E X

string methods 59–60 find method 60–61 join method 61–62 lower method 62 replace method 62 split method 63 strip method 63

translate method 64–65 string representations 25 Unicode strings 29

strip method 63 strptime function

time module 227 sub method

adding to handler superclass 398 sub function

re module 239, 240 subclassing

built-in classes 173

list, dict, and str 182–184 subprocess module

running the Tidy program 317 using command-line tools 352

subprocess module speeding up programs 361

substitutions

using group numbers and functions in 242–243

sum function 561 sunspots example

creating line diagram from data 411 first implementation 413

constructing some polylines 415 drawing with ReportLab 413–414 prototype 416

preparations 412

second implementation 417 getting the data 417–418 using LinePlot class 418

super function using 178–179

working on old style classes 173 superclasses

multiples 154–155 specifying 153

Surface function pygame module 528

SWIG tool 361

compiling, linking, and using 364–365 detecting palindromes 362–363 extending Python 358

installing 362 interface file 363 introduction 361 running 363 using 362

synchronous network programming 298 SyntaxError class 161

sys module example 216

functions and variables 215 getdefaultencoding function 436 setdefaultencoding function 436

system function os module 217

T

TCPServer class SocketServer module 303

telephone book example 70 revised 78

tell method

file object 260 telnetlib module 302 Template class

string Module 72 template strings 54

Test-Driven Development

Beck, Kent et al 387

I N D E X 601

TestCase class methods 348 unittest module 347

test-driven programming 341, 344 testing 341

alternatives to unit testing 350 profiling 353–354

PyChecker and PyLint 351–353 code coverage 343

planning for change 343 requirement specification 342–343 test-driven development process 344 tools for testing 344

doctest tool 344–346 unittest module 347–349

unit testing 341 testmod function

doctest tool 345–346

TEX-based typography

PYX support for 412

text editor application example elements 270

requirements 269 textwrap module 336

Thomas, David and Hunt, Andrew

Pragmatic Programmer, The 387 threading

multiple connections 304 SocketServer module 305

threading module 501 threadsafety module property

Python DB API 286

Tidy 314

getting Tidy library 316 introduction 315–316

using command-line Tidy 317 time function

time module 441

time module 440, 501

functions required for news project 441 introduction 226–227

time function

time module 227 timeit module 227, 251

profiling 353 TinyFugue 457

Tkinter GUI toolkit 271, 573 example of using 281–282

trace module 251 trace.py program 343 tracebacks 159

cgitb module 486 translate method 60, 64–65 translation tables 64 trapping exceptions162 truth values 86

try statements 570 try/except statements 169

adding except clause 164 catching exceptions 162 compared to if/else 170

try/finally statements closing files 261 tuple function 50, 561 tuples 31, 49, 50, 55, 56

basic tuple operations 50 conversion specifiers 55 tuple function 50

uses 51 Twisted

downloading and installing 308 writing a Twisted server 309

Twisted framework

LineReceiver class 455

twisted.internet.protocol module Factory class 309

602I N D E X

twisted.internet.reactor module listenTCP function 309

twisted.protocols.basic module LineReceiver protocol 310

type function 561 type objects 18

TypeError class 161, 180, 182, 193 types

and classes 147–148

U

UDPServer class SocketServer module 303

unichr function 561 unicode function 561 Unicode strings 29 uniform function

random module 228 union method

set type 222 unit testing 341

unittest module 347–349 TestCase class 347

test-first, code-later programming 345 Unix

setting environment variables 209 UnixDatagramServer class

SocketServer module 303

UnixStreamServer class

SocketServer module 303 unquote function

urllib module 301 unquote_plus function urllib module 301

update function

pygame.display module 529, 532 update method 77

Group class 532 upper method 91

urandom function os module 217, 228

urandom variable os module 217 urlcleanup function

urllib module 301 urlencode function urllib module 301

urllib module 297 functions 301

network programming 300 urlcleanup function 301 urlopen function 300, 301, 417 urlretrieve function 301

urllib2 module

network programming 300 urlopen function

urllib module 300, 301, 417 urlparse module 302, 501 urlretrieve function

urllib module 301 user input, getting 15–16 UserDict module

inheriting from class 183 UserList module

inheriting from class 183 UserString module

inheriting from class 183

V

ValueError class 161 values method

dictionaries 77 variables 13

vars function 562 virtual tea party 455

first implementation 457 ChatServer class 457–459 ChatSession class 459–463

further exploration 472 goals 455 preparations 456–457 problem 455

second implementation 463

basic command interpretation 463–464 login and logout rooms 465

main chat room 466 new server 466–472 rooms 464–465

tools 456

W

Warning exception class 287 warnings

exceptions as 159 Weave tool

speeding up programs 361 Web programming

dynamic pages with CGI 321

adding the Pound Bang line 321–322 CGI security risks 323

debugging with cgitb 324 preparing the Web server 321 setting file permissions 322 simple CGI script 323–324 simple form 327–328

using cgi module 325–326 mod_python 328

CGI handler 330–331 configuring Apache 330 installing 329 installing on Unix 329

installing on Windows 329 PSP 331–332

Publisher 332–334 screen scraping 313–314

Beautiful Soup module 319–320

HTMLParser 318–319

Tidy 314–317

I N D E X 603

Web services 335

RSS 335–336

XML-RPC 337–338

Web services RSS 335–336 scraping 335

XML-RPC 337–338 webbrowser module open function 218

while loops 94, 569

using readline method, file object 264 while True/break idiom 99–100 win32all 571

Windows

installing Python 1–2

setting environment variables 209 wininst format

Distutils installer 378

Wise installer

installing Distutils toolkit 378 write method

file object 258 stdout class 310

writeline method file object 260, 261

wx constructors

using keyword arguments 274 wx module

importing 272 style facets 276 wx.App class 272, 518

MainLoop method 273 wx.BoxSizer class 276 wx.Button class

adding button to frame 273 wx.Frame class

Show method 273

windows as instances of 273

604I N D E X

wx.Panel class SetSizer method 276

wxPython GUI toolkit 271, 573 adding GUI to files 517

downloading and installing 271–272 event handling 278

finished program 278–280 getting started 272

labels and positions 274–276 layout 276–277

writing programs 273

X

XHTML

reasons for using 317 XML files

parsing 421–422

special characters 436

XML for all occasions project 421 first implementation 424

creating a simple content handler 425–427

creating HTML pages 428–429 further exploration 437

goals 422

parsing XML files 421–422 preparations 423–424 second implementation 430

dispatcher mix-in class 430–432 event handlers 433–436

factoring out header, footer, and default handling 432

support for directories 432–433 tools 422

xml.sax module parse function 425

xml.sax.handler module ContentHandler class 425

XML-RPC

file sharing with 499–516

introduction 337–338 xmlrpclib module 302, 337, 501

Fault class 510 importing 501 xrange function 562 xreadlines method file object 263

lazy line iteration 265

Y

yield statements 192, 194, 567

Z

Zawinski, Jamie 235 ZeroDivisionError class 159, 161, 555

catching with except clause 164 exceptions 168

muffling 163 zero-padding 58 zip function 562

parallel iteration 97 Zope 313