- Page 2 and 3:
Table of Contents | Index Core Pyth
- Page 4 and 5:
The Complete Developer's Guide to P
- Page 6 and 7:
Table of Contents | Index Copyright
- Page 8 and 9:
Section 6.2. Strings Section 6.3. S
- Page 10 and 11:
Section 11.5. Formal Arguments Sect
- Page 12 and 13:
Section 19.4. Brief Tour of Other G
- Page 14 and 15:
Copyright Many of the designations
- Page 16 and 17:
Praise for Core Python Programming
- Page 18 and 19:
Prentice Hall Core Series Core J2EE
- Page 20 and 21:
Another set of first edition reader
- Page 22 and 23:
We will continue to update the book
- Page 24 and 25:
Dictionaries are Python's mapping o
- Page 26 and 27:
and you will find it fun! We first
- Page 28 and 29:
Acknowledgments Acknowledgments for
- Page 30 and 31:
Christian Tismer (creator of Stackl
- Page 32 and 33:
Chapter 1. Welcome to Python! Chapt
- Page 34 and 35:
1.2. Origins Work on Python began i
- Page 36 and 37:
which you can build an application,
- Page 38 and 39:
often provides an extended distract
- Page 40 and 41:
Build It Yourself For most other pl
- Page 42 and 43:
Windows/DOS To add Python to your s
- Page 44 and 45:
It is also possible in Unix to auto
- Page 46 and 47:
MacOS X is very Unix-like (based on
- Page 48 and 49:
Figure 1-5. Starting IDLE in Window
- Page 50 and 51:
1.6. Python Documentation Python do
- Page 52 and 53:
orrow features from languages such
- Page 54 and 55:
1.8. Other Implementations The "sta
- Page 56 and 57:
1.9. Exercises 1-1. Python Installa
- Page 58 and 59:
abs(4) 4 >>> abs(-4) 4 We will intr
- Page 60 and 61:
%s means to substitute a string whi
- Page 62 and 63:
It's very tempting for beginners to
- Page 64 and 65:
2.4. Operators The standard mathema
- Page 66 and 67:
2.5. Variables and Assignment Rules
- Page 68 and 69:
All numeric types are covered in Ch
- Page 70 and 71:
2.8. Lists and Tuples Lists and tup
- Page 72 and 73:
2.10. Code Blocks Use Indentation C
- Page 74 and 75:
2.12. while Loop The standard while
- Page 76 and 77:
Using the string format operator al
- Page 78 and 79:
2.14. List Comprehensions These are
- Page 80 and 81:
case you would have to revert back
- Page 82 and 83:
2.17. Functions Like many other lan
- Page 84 and 85:
2.18. Classes Classes are a core pa
- Page 87 and 88:
2.19. Modules A module is a logical
- Page 89 and 90:
2.20. Useful Functions In this chap
- Page 91 and 92:
2-4. User Input with raw_input(). a
- Page 93 and 94:
put in your own as you write your c
- Page 95 and 96:
Chapter 3. Python Basics Chapter To
- Page 97 and 98:
3.1.3. Multiple Statement Groups as
- Page 99 and 100:
3.2. Variable Assignment This secti
- Page 101:
Another way of assigning multiple v
- Page 104 and 105:
[a] access keyword obsoleted as of
- Page 106 and 107:
three PEPs: 7 (Style Guide for C Co
- Page 108 and 109:
3. Module imports Import all the mo
- Page 110 and 111:
Tests in the main body are an easy
- Page 112 and 113:
As responsible programmers, we are
- Page 114 and 115:
● It is explicitly removed from a
- Page 116 and 117:
Lines 13 The Unix startup line is f
- Page 118 and 119:
1 #!/usr/bin/env python 2 3 'readTe
- Page 120 and 121:
3.7. Related Modules/Developer Tool
- Page 122 and 123:
3-10. Exceptions. Replace the call
- Page 124 and 125:
4.1. Python Objects Python uses the
- Page 126 and 127:
4.3. Other Built-in Types ● Type
- Page 128 and 129:
4.4. Internal Types ● Code ● Fr
- Page 130 and 131:
4.5. Standard Type Operators 4.5.1.
- Page 132 and 133:
Example 2: foo1 and foo2 reference
- Page 134 and 135:
4.5.3. Boolean In the above example
- Page 136 and 137:
4.6. Standard Type Built-in Functio
- Page 138 and 139:
str(2e10) '20000000000.0' >>> >>> s
- Page 140 and 141:
>>> type(foo) # assumes foo instant
- Page 142 and 143:
then we do not even need to check b
- Page 144 and 145:
4.7. Type Factory Functions Since P
- Page 146 and 147:
Another way of categorizing the sta
- Page 148:
Sequence types are those whose elem
- Page 151 and 152:
4.10. Exercises 4-1. Python Objects
- Page 153 and 154:
Chapter 5. Numbers Chapter Topics
- Page 155 and 156:
Okay, now that you have a good idea
- Page 157 and 158:
Core Style: Use uppercase "L" with
- Page 159 and 160:
5.3. Double Precision Floating Poin
- Page 161 and 162:
aComplex.real -8.333 >>> aComplex.i
- Page 163 and 164:
Automatic numeric coercion makes li
- Page 165 and 166:
True Division This is where divisio
- Page 167 and 168:
see that the unary operator binds m
- Page 169 and 170:
Bitwise Operator Function ~num (una
- Page 171 and 172:
In addition, because of the unifica
- Page 173 and 174:
divmod(10,2.5) (4.0, 0.0) >>> divmo
- Page 175 and 176:
floor(-1.2) -2.0 round(-1.2) -1.0 -
- Page 178 and 179:
5.7. Other Numeric Types 5.7.1. Boo
- Page 180 and 181:
cannot "be continued." If we were t
- Page 182 and 183:
uniform() Does almost the same thin
- Page 184 and 185:
5.9. Exercises The exercises in thi
- Page 186 and 187:
Why do we get 134L and not 1342 in
- Page 188 and 189:
Chapter 6. Sequences: Strings, List
- Page 190 and 191:
obj not in seq Tests if obj is not
- Page 192 and 193:
if not provided, or if None is used
- Page 194 and 195:
Extended Slicing with Stride Indice
- Page 196 and 197:
above. 6.1.3. Built-in Functions (B
- Page 198 and 199:
[a] New in Python 2.3. [b] key argu
- Page 200 and 201:
considered a substring. To access s
- Page 202 and 203:
6.3. Strings and Operators 6.3.1. S
- Page 204 and 205:
Notice how the omission of both ind
- Page 206 and 207:
numeric identifier strings that we
- Page 208 and 209:
method (see example below). There i
- Page 210 and 211:
6.4. String-Only Operators 6.4.1. F
- Page 212 and 213:
'6c' >>> >>> "%X" % 108 '6C' >>> >>
- Page 214 and 215:
>>> print s.substitute(lang='Python
- Page 216 and 217:
6.5. Built-in Functions 6.5.1. Stan
- Page 218 and 219:
isinstance() calls to verify type:
- Page 220 and 221:
string.isalpha() [a] , [b] [c] Retu
- Page 222 and 223:
>>> quest.endswith('color?') True >
- Page 224 and 225:
\t 011 9 0x09 HT Horizontal tab \n
- Page 226:
string was created when the operati
- Page 229 and 230:
convert the numeric value of the by
- Page 231 and 232:
Example 6.2. Simple Unicode String
- Page 233 and 234:
Mistake #2: Using the string module
- Page 236 and 237:
6.9. Related Modules Table 6.10 lis
- Page 238:
6.10. Summary of String Highlights
- Page 241 and 242:
How to Update Lists You can update
- Page 243 and 244:
str_list[2] 'over' >>> str_list[:2]
- Page 245:
Traceback (innermost last): File ""
- Page 248 and 249:
3. 4. 5. If elements are of the sam
- Page 250 and 251:
sum(a, 5) 20 >>> a = [6., 4., 5.] >
- Page 252 and 253:
[a] Removes and returns obj at give
- Page 254 and 255:
original list object is left as is,
- Page 256 and 257:
28 while True: 29 while True: 30 tr
- Page 258 and 259:
(Q)uit Enter choice: v You picked:
- Page 260 and 261:
Line-by-Line Explanation Because of
- Page 262 and 263:
6.16. Tuples Tuples are another con
- Page 264 and 265:
6.17. Tuple Operators and Built-in
- Page 266 and 267:
6.18. Special Features of Tuples 6.
- Page 268 and 269:
(4, True, 5) >>> (4, 2) < (3, 5) #
- Page 270 and 271:
6.19. Related Modules Table 6.12 li
- Page 272 and 273:
[id(x) for x in hubby] [9919616, 11
- Page 274 and 275:
6.21. Summary of Sequences Sequence
- Page 276 and 277:
str() • • • strip() • swapc
- Page 278 and 279:
d. Take a string and append a backw
- Page 280 and 281:
6-12. Strings. a. b. c. Create a fu
- Page 282 and 283:
6-19. Multi-Column Output. Given an
- Page 284 and 285:
7.1. Mapping Type: Dictionaries Dic
- Page 286 and 287:
dict2 = {'name': 'earth', 'port': 8
- Page 288 and 289:
dict2['arch'] = 'sunos5' # add new
- Page 290 and 291:
Beginning with Python 2.2, programm
- Page 292 and 293:
size, their keys match, and so do t
- Page 294 and 295:
dict(zip(('x', 'y'), (1, 2))) {'y':
- Page 296 and 297:
7.4. Mapping Type Built-in Methods
- Page 298 and 299:
dict2= {'host':'earth', 'port':80}
- Page 300 and 301:
7.5. Dictionary Keys Dictionary val
- Page 302 and 303:
39 try: 40 choice = raw_input(promp
- Page 304 and 305:
7.6. Set Types In mathematics, a se
- Page 306 and 307:
... print i ... c e h o p s How to
- Page 308 and 309:
superset of the second set (is a su
- Page 310 and 311:
s &= set('shop') >>> s set(['h', 's
- Page 312 and 313:
7.9. Set Type Built-in Methods 7.9.
- Page 314 and 315:
7.10. Operator, Function/Method Sum
- Page 316 and 317:
7.11. Related Modules The sets modu
- Page 318 and 319:
7-5. userpw2.py. The following prob
- Page 320 and 321:
characters in srcstr that are beyon
- Page 322 and 323:
Chapter 8. Conditionals and Loops C
- Page 324 and 325:
8.2. else Statement Like other lang
- Page 326 and 327:
8.3. elif (aka else-if) Statement e
- Page 328:
8.4. Conditional Expressions (aka "
- Page 331 and 332:
One must use caution when using whi
- Page 333 and 334:
Iterating by Sequence Item >>> name
- Page 335 and 336:
ange(start, end, step=1) range() wi
- Page 337 and 338:
are "sequence-related" is that half
- Page 339 and 340:
8.8. continue Statement Core Note:
- Page 341 and 342:
8.10. else Statement ... Take Two I
- Page 343 and 344:
8.11. Iterators and the iter() Func
- Page 345 and 346:
Dictionaries Dictionaries and files
- Page 347 and 348:
8.12. List Comprehensions List comp
- Page 349 and 350:
and split each line up into words,
- Page 351 and 352:
of building up this long list, it w
- Page 353 and 354:
lines)? That way, we can use the ma
- Page 355 and 356:
8.15. Exercises 8-1. Conditionals.
- Page 357 and 358:
8-9. Fibonacci Numbers. The Fibonac
- Page 360 and 361:
Chapter 9. Files and Input/Output C
- Page 362 and 363:
9.2. File Built-in Functions [open(
- Page 364 and 365:
you see references to open(), you c
- Page 366 and 367:
Note that there is no "writeline()"
- Page 368 and 369:
We originally described how this pr
- Page 370 and 371:
f.seek(-12, 1) # move back 12 bytes
- Page 372 and 373:
9.4. File Built-in Attributes File
- Page 374 and 375:
9.6. Command-Line Arguments The sys
- Page 376 and 377:
9.7. File System Access to your fil
- Page 378 and 379:
Separation basename() Remove direct
- Page 380 and 381:
53 print '*** deleting test file' 5
- Page 382 and 383:
to confirm that the directory is in
- Page 384 and 385:
9.8. File Execution Whether we want
- Page 386 and 387:
other external extension modules th
- Page 388 and 389:
9.10. Related Modules There are ple
- Page 390 and 391:
Some other Python modules that gene
- Page 392 and 393:
9-10. Home Finances. Create a home
- Page 394 and 395:
9-15. Copying Files. Prompt for two
- Page 396 and 397:
9-24. File Transfer Between Archive
- Page 398 and 399:
10.1. What Are Exceptions? 10.1.1.
- Page 400 and 401:
10.2. Exceptions in Python As you w
- Page 402 and 403:
our case with the foo (non-)attribu
- Page 404 and 405:
As you can see, our code now runs s
- Page 406 and 407:
etval = None return retval Bear in
- Page 408 and 409:
except (Exc1[, Exc2[, ... ExcN]])[,
- Page 410 and 411:
except Exception, e: # handle real
- Page 412 and 413:
try: ... float(['float() does not',
- Page 414 and 415:
13 log = open('cardlog.txt', 'w') 1
- Page 416 and 417:
determine whether there were defect
- Page 418 and 419:
log.write('no txns this month\n') f
- Page 420 and 421: 10.4. Context Management 10.4.1. wi
- Page 422 and 423: Now the with_suite executes. When e
- Page 424 and 425: 10.6. Raising Exceptions The interp
- Page 426 and 427: aise string, args, tb Same as above
- Page 428 and 429: try: assert 1 == 0, 'One does not e
- Page 430 and 431: [d] Error in FloatingPointError flo
- Page 432 and 433: [h] Unicode- UnicodeError related e
- Page 434 and 435: 10.9. *Creating Exceptions Although
- Page 436 and 437: 79 f.close() 80 81 for eachTest in
- Page 438 and 439: the host's name and the port number
- Page 440 and 441: 10.10. Why Exceptions (Now)? There
- Page 442 and 443: 10.12. Exceptions and the sys Modul
- Page 444 and 445: 10.14. Exercises 10-1. Raising Exce
- Page 446 and 447: 10-9. Improving math.sqrt(). The ma
- Page 448 and 449: 11.1. What Are Functions? Functions
- Page 450 and 451: Stated Number of Objects to Return
- Page 452 and 453: Keyword arguments may also be used
- Page 454 and 455: Line-by-Line Explanation Lines 14 O
- Page 456 and 457: 11.3. Creating Functions 11.3.1. de
- Page 458 and 459: modules foo and bar, but can use th
- Page 460 and 461: The main motivation behind decorato
- Page 462 and 463: func = deco1(deco_arg)(deco2(func))
- Page 464 and 465: 11.4. Passing Functions The concept
- Page 466 and 467: 11.5. Formal Arguments A Python fun
- Page 468 and 469: mandatory, whereas default argument
- Page 472 and 473: print 'formal arg 1:', arg1 print '
- Page 474 and 475: additional non-keyword arg: 30 addi
- Page 476 and 477: int('1234') = 1234 int('12.34') = F
- Page 478 and 479: visualize their lambda equivalents.
- Page 480 and 481: all of them take a function object
- Page 482 and 483: $ python oddnogen.py [39, 77, 39, 7
- Page 484 and 485: We have also discussed how map () c
- Page 486 and 487: · def mySum(x,y): return x+y · la
- Page 488 and 489: >>> add1(10) 11 >>> add1(1) 2 >>> m
- Page 490 and 491: Why bother with so much repetition
- Page 492 and 493: It is possible to "hide" or overrid
- Page 494 and 495: If references are made from inside
- Page 496 and 497: 14 print output % ('w', id(w), w) 1
- Page 498 and 499: 21 try: 22 return f(*args, **kargs)
- Page 500 and 501: File "", line 3, in NameError: y I
- Page 502 and 503: 17 k = 7 18 proc1() 19 print "j ==
- Page 504 and 505: 11.10. Generators Earlier in Chapte
- Page 506 and 507: generator, but serves as a short fo
- Page 508 and 509: 11.11. Exercises 11-1. Arguments. C
- Page 510 and 511: 11-10. Functional Programming with
- Page 512 and 513: Chapter 12. Modules Chapter Topics
- Page 514 and 515: 12.2. Modules and Files If modules
- Page 516 and 517: 12.3. Namespaces A namespace is a m
- Page 518 and 519: ar = 100 print "in __main__, bar is
- Page 520 and 521:
12.4. Importing Modules 12.4.1. The
- Page 522 and 523:
workaround is to assign the module
- Page 524 and 525:
In practice, using from module impo
- Page 526 and 527:
and RuntimeWarning. These are descr
- Page 528 and 529:
12.6. Module Built-in Functions The
- Page 530 and 531:
12.7. Packages A package is a hiera
- Page 532:
The rationale behind this decision
- Page 535 and 536:
The world was pretty clean-cut when
- Page 537 and 538:
The workaround for this problem is
- Page 539 and 540:
12.10. Exercises 12-1. PathSearch v
- Page 541 and 542:
Chapter 13. Object-Oriented Program
- Page 543 and 544:
Classes and Instances Classes and i
- Page 545 and 546:
chapter, these attributes really ar
- Page 547 and 548:
>>> john.name 'John Doe' >>> john.p
- Page 549 and 550:
"AddrBookEntry," "RepairShop," etc.
- Page 551 and 552:
Person would include the Customer,
- Page 553 and 554:
13.3. Classes Recall that a class i
- Page 555 and 556:
13.4. Class Attributes What is an a
- Page 557 and 558:
In keeping with OOP tradition, Pyth
- Page 559 and 560:
eturns a type object when invoked.
- Page 561 and 562:
13.5. Instances Whereas a class is
- Page 563 and 564:
13.5.3. __new__() "Constructor" Met
- Page 565 and 566:
= InstTrack() >>> b.howMany() 2 >>>
- Page 567 and 568:
arguments in Section 11.5.2. One ca
- Page 569 and 570:
dir(c) ['__class__', '__delattr__',
- Page 571 and 572:
1.0 >>> x.conjugate() (1-2j) Attemp
- Page 573 and 574:
But... all of this changes if the c
- Page 575 and 576:
13.7. Binding and Method Invocation
- Page 577 and 578:
13.8. Static Methods and Class Meth
- Page 579 and 580:
13.9. Composition Once a class is d
- Page 581 and 582:
print 'calling parent method' class
- Page 583 and 584:
created an instance of C >>> c.__cl
- Page 585 and 586:
Core Note: Overriding __init__ does
- Page 587 and 588:
class RoundFloat(float): def __new_
- Page 589 and 590:
Simple Attribute Lookup Example The
- Page 591 and 592:
(, , , , , ) *MRO Problems Caused b
- Page 593 and 594:
13.12. Built-in Functions for Class
- Page 595 and 596:
class myClass(object): ... def __in
- Page 597 and 598:
c.foo = 100 >>> c.bar = 'Python' >>
- Page 599 and 600:
Object (Value) Comparison [c] C.__c
- Page 601 and 602:
[f] Test sequence membership; in ke
- Page 603 and 604:
subclass anything (except object of
- Page 605 and 606:
1 #!/usr/bin/env python 2 3 class R
- Page 607 and 608:
mon - tue Traceback (most recent ca
- Page 609 and 610:
The answer is yes, you can, and it
- Page 611 and 612:
14-21). In the last part of next(),
- Page 613 and 614:
17 other.__num, \ 18 self.__string
- Page 615 and 616:
Not calling repr() on self.__string
- Page 617 and 618:
13.14. Privacy Attributes in Python
- Page 619 and 620:
Delegation is a characteristic of w
- Page 621 and 622:
dictionaries fails to find a succes
- Page 623 and 624:
38 39 def __getattr__(self, attr):
- Page 625 and 626:
code is identical to what you would
- Page 627 and 628:
OLD (not as good): BETTER: ● if t
- Page 629 and 630:
The signatures for __get__(), __set
- Page 631 and 632:
class C2(object): ... foo = DevNull
- Page 633 and 634:
Lines 2838 Saving the attribute tak
- Page 635 and 636:
Believe it or not, you have already
- Page 637 and 638:
class PI(object): pi = property(get
- Page 639 and 640:
if it is there, it will use the cla
- Page 641 and 642:
stacklevel=3) We will create three
- Page 643 and 644:
13.17. Related Modules and Document
- Page 645 and 646:
There are plenty of class, and obje
- Page 647 and 648:
Extra credit: Allow the user to opt
- Page 649 and 650:
13-7. Date Class. Provide an interf
- Page 651 and 652:
13-12. Chat Rooms. You have been pr
- Page 653 and 654:
d. e. f. In addition to instantiati
- Page 655 and 656:
14.1. Callable Objects A number of
- Page 657 and 658:
Internally, user-defined functions
- Page 659 and 660:
immediately garbage-collected. The
- Page 661 and 662:
callable(c) # instance is callable
- Page 663 and 664:
14.3. Executable Object Statements
- Page 665 and 666:
1 2 3 4 5 In the final example, we
- Page 667 and 668:
Note that once execution has comple
- Page 669 and 670:
22 print %s 23 %s = %s + %d 24 """
- Page 671 and 672:
3.0 arrrghhh ----------------------
- Page 673 and 674:
Calling sys.exit() causes the Pytho
- Page 675 and 676:
14.4. Executing Other (Python) Prog
- Page 677 and 678:
Earlier in this chapter, we describ
- Page 679 and 680:
14.5. Executing Other (Non-Python)
- Page 681 and 682:
from the interactive interpreter so
- Page 683 and 684:
type, operating system name, etc. A
- Page 685 and 686:
GNU/Linux >>> f = Popen('who', stdo
- Page 687 and 688:
14.7. Terminating Execution Clean e
- Page 689 and 690:
We execute the old exit function af
- Page 691 and 692:
[a] New in Python 2.3.
- Page 693 and 694:
14.10. Exercises 14-1. Callable Obj
- Page 695 and 696:
Part II: Advanced Topics Chapter 15
- Page 697 and 698:
15.1. Introduction/Motivation Manip
- Page 699 and 700:
with which to recognize multiple st
- Page 701 and 702:
\s Match any whitespace character,
- Page 703 and 704:
While the dot is good for allowing
- Page 705 and 706:
Using these shortcuts, we will pres
- Page 707 and 708:
15.3. REs and Python Now that we kn
- Page 709 and 710:
make function calls with the same s
- Page 711 and 712:
The chances are greater that the pa
- Page 713 and 714:
m = re.match('r2d2|c3po', 'c2do') #
- Page 715 and 716:
'ab' >>> m.group(2) # subgroup 2 'b
- Page 717 and 718:
% who wesc console Jun 20 20:33 wes
- Page 719 and 720:
You may have seen the use of raw st
- Page 721 and 722:
Sat May 5 16:36:23 1990::fclihw@alw
- Page 723 and 724:
Both of the above REs are the most
- Page 725 and 726:
patt = '.+?(\d+-\d+-\d+)' >>> re.ma
- Page 727 and 728:
15-13. type(). The type() built-in
- Page 729 and 730:
Chapter 16. Network Programming Cha
- Page 731 and 732:
System (NFS). If you are accessing
- Page 733 and 734:
includes any necessary exchange of
- Page 735 and 736:
other end; otherwise, you get the f
- Page 737 and 738:
16.3. Network Programming in Python
- Page 739 and 740:
networked applications In our multi
- Page 741 and 742:
22 if not data: 23 break 24 tcpCliS
- Page 743 and 744:
The TCP client socket (tcpCliSock)
- Page 745 and 746:
Creates a UDP server that accepts m
- Page 747 and 748:
way as the UDP server. Lines 1222 O
- Page 749 and 750:
[b] Convert IP address string to pa
- Page 751 and 752:
consists of an event handler for th
- Page 753 and 754:
This is a timestamp TCP client that
- Page 755 and 756:
16.5. *Introduction to the Twisted
- Page 757 and 758:
Our familiar timestamp TCP client w
- Page 759:
16.6. Related Modules Table 16.4 li
- Page 762 and 763:
16-7. Half-Duplex Chat. Create a si
- Page 764 and 765:
Chapter 17. Internet Client Program
- Page 766 and 767:
17.2. Transferring Files 17.2.1. Fi
- Page 768 and 769:
So how do we write an FTP client us
- Page 770 and 771:
drwxr-xr-x 3 root wheel 512 May 19
- Page 772 and 773:
allocated rather than depending on
- Page 774 and 775:
17.3. Network News 17.3.1. Usenet a
- Page 776 and 777:
from nntplib import NNTP n = NNTP('
- Page 778 and 779:
Finally, we are going to do blank l
- Page 780 and 781:
75 count += 1 76 lastBlank = False
- Page 782 and 783:
lines making up the article body an
- Page 784 and 785:
In order to send e-mail, your mail
- Page 786 and 787:
[a] SMTP-AUTH only. 17.4.5. Interac
- Page 788 and 789:
interested reader to the aforementi
- Page 790 and 791:
17.4.11. poplib.POP3 Class Methods
- Page 792 and 793:
(s). Line 14 puts everything togeth
- Page 794 and 795:
Module Description ftplib FTP proto
- Page 796 and 797:
NNTP 17-7. Recursion. The ftpmirror
- Page 798 and 799:
17-21. IMAP. Now that you are famil
- Page 800 and 801:
17-30. * Developing New Internet Cl
- Page 802:
18.1. Introduction/Motivation Befor
- Page 805 and 806:
18.3. Python, Threads, and the Glob
- Page 807 and 808:
Let us create two "time loops," one
- Page 809 and 810:
18.4. tHRead Module Let's take a lo
- Page 811 and 812:
We did not have any code that told
- Page 813 and 814:
As hinted in the earlier Core Note,
- Page 815 and 816:
18.5.1. Thread Class Another reason
- Page 817 and 818:
28 29 print 'all DONE at:', ctime()
- Page 819 and 820:
loop 0 done at: Sun Aug 13 18:49:21
- Page 821 and 822:
To generalize our subclass of Threa
- Page 823 and 824:
233 fib finished at: Sun Jun 18 19:
- Page 825 and 826:
18 def writer(queue, loops): 19 for
- Page 827 and 828:
18.6. Related Modules The table bel
- Page 829 and 830:
18-10. Take your solution to the pr
- Page 831 and 832:
19.1. Introduction 19.1.1. What Are
- Page 833 and 834:
19.2. Tkinter and Python Programmin
- Page 835 and 836:
created by the Tk class in Tkinter
- Page 837 and 838:
19.3. Tkinter Examples 19.3.1. Labe
- Page 839 and 840:
This example features both a Label
- Page 841 and 842:
Figure 19-4. Tkinter Label, Button,
- Page 843 and 844:
29 30 MyButton = pto(Button, top) 3
- Page 845 and 846:
13 self.label.pack() 14 15 self.cwd
- Page 847 and 848:
The Unix version of this applicatio
- Page 849 and 850:
number of files exceeds the size of
- Page 851 and 852:
19.4. Brief Tour of Other GUIs We h
- Page 853 and 854:
Our first example uses the Tix modu
- Page 855 and 856:
Our third example uses wxPython (an
- Page 857 and 858:
15 'Animals (in pairs; min: pair, m
- Page 859 and 860:
19.5. Related Modules and Other GUI
- Page 861 and 862:
19.6. Exercises 19-1. Client/Server
- Page 863 and 864:
Chapter 20. Web Programming Chapter
- Page 865 and 866:
and values chained as part of the r
- Page 867 and 868:
20.2. Web Surfing with Python: Crea
- Page 869 and 870:
scheme in case one is not provided
- Page 871 and 872:
If the "POST" request method is des
- Page 873 and 874:
28 ldir = dirname(path) # local dir
- Page 875 and 876:
final = '%s?name=%s&num=%d' % (base
- Page 877 and 878:
This script uses both techniques de
- Page 879 and 880:
20.3. Advanced Web Clients Web brow
- Page 881 and 882:
* http://www.null.com/home/overview
- Page 883 and 884:
Forms input from the client sent to
- Page 885 and 886:
20.5. Building CGI Applications 20.
- Page 887 and 888:
Figure 20-5. Friends form page in I
- Page 889 and 890:
If you are a Web site producer, you
- Page 891 and 892:
55 else: 56 showForm() 57 58 if __n
- Page 893 and 894:
If you look at the location or "Go
- Page 895 and 896:
71 error = 'Please select number of
- Page 897 and 898:
We click on the "Back" button, chec
- Page 899 and 900:
20.6. Using Unicode with CGI In Cha
- Page 901 and 902:
20.7. Advanced CGI We will now take
- Page 903 and 904:
Figure 20-14. Upload and multivalue
- Page 905 and 906:
The data are submitted to the serve
- Page 907 and 908:
When the script detects no form dat
- Page 909 and 910:
55 split(self.cookies['info'], ':')
- Page 911 and 912:
172 self.langs.append(eachLang.valu
- Page 913 and 914:
four-megabyte binary file.
- Page 915 and 916:
Module Description BaseHTTPServer P
- Page 917 and 918:
20.9. Related Modules In Table 20.7
- Page 919 and 920:
inascii En-/decodes data using base
- Page 921 and 922:
20-7. Count how many of each type o
- Page 923 and 924:
20-24. Advanced Web Clients. The cr
- Page 925 and 926:
21.1. Introduction 21.1.1. Persiste
- Page 927 and 928:
Inserting a Row INSERT INTO users V
- Page 929 and 930:
21.2. Python Database Application P
- Page 931 and 932:
Parameter Description user Username
- Page 933 and 934:
The commit() method is irrelevant i
- Page 935 and 936:
Table 21.7. Type Objects and Constr
- Page 937 and 938:
later on in this chapter. Let us no
- Page 939 and 940:
import psycopg >>> cxn = psycopg.co
- Page 941 and 942:
MySQL, but which does a few more th
- Page 943 and 944:
82 uid INTEGER, 83 prid INTEGER) 84
- Page 945 and 946:
The guts of consistent database acc
- Page 947 and 948:
The director of this movie is main(
- Page 949 and 950:
Example 21.2. SQLAlchemy ORM Exampl
- Page 951 and 952:
112 113 if__name__ == '__main__': 1
- Page 953 and 954:
103 print '\n*** Dropping users tab
- Page 955 and 956:
(3 users moved) LOGIN USERID PROJ#
- Page 957 and 958:
Jess 7912 1 Amy 7209 4 Melissa 8602
- Page 959 and 960:
21.4. Related Modules Table 21.8 li
- Page 961 and 962:
21.5. Exercises 21-1. Database API.
- Page 963 and 964:
22.1. Introduction/Motivation 22.1.
- Page 965 and 966:
22.2. Extending Python by Writing E
- Page 967 and 968:
To run our program, we issue the fo
- Page 969 and 970:
Python to C int PyArg_ParseTuple()
- Page 971 and 972:
of the string.) strdup() creates an
- Page 973 and 974:
The next step is to create a setup.
- Page 975 and 976:
Test Function The one last thing we
- Page 977 and 978:
59 if (!PyArg_ParseTuple(args, "s",
- Page 979 and 980:
As with the reference counting macr
- Page 981 and 982:
has the effect of giving a potentia
- Page 983 and 984:
Chapter 23. Miscellaneous Chapter T
- Page 985 and 986:
['YHOO', '30.76', '5/23/2006', '4:0
- Page 987 and 988:
If we run this script, we will get
- Page 989 and 990:
consider for the general audience.
- Page 991 and 992:
On line 13, we use what is known as
- Page 993 and 994:
20 sleep(1) 21 for i in RANGE: 22 r
- Page 995 and 996:
In our example, we just use a (titl
- Page 997 and 998:
olFolderDrafts (16), olFolderSentMa
- Page 999 and 1000:
This script downloads stock quotes
- Page 1001 and 1002:
decimal point, e.g., "34.2" is disp
- Page 1003 and 1004:
write a GUI application using Swing
- Page 1005 and 1006:
Jython is a great development tool
- Page 1007 and 1008:
23-8. Microsoft Outlook and Web Ser
- Page 1009 and 1010:
Java, Python, Jython 23-16. Jython.
- Page 1011 and 1012:
Appendix A. Answers to Selected Exe
- Page 1013 and 1014:
Chapter 2 5. Loops and numbers a. b
- Page 1015 and 1016:
Chapter 3 4. Statements Use; 5. Sta
- Page 1017 and 1018:
Chapter 5 8. Geometry import math d
- Page 1019 and 1020:
Chapter 6 1. Strings find(), rfind(
- Page 1021 and 1022:
7. Inverting dictionaries list1 = o
- Page 1023 and 1024:
Chapter 9 2. File access f = open(r
- Page 1026 and 1027:
Chapter 11 2. Functions def sumtime
- Page 1028 and 1029:
Chapter 13 2. Functions versus meth
- Page 1030 and 1031:
Chapter 15 1. Matching strings bat,
- Page 1032 and 1033:
Chapter 16 3. Sockets TCP 6. Daytim
- Page 1034 and 1035:
Chapter 18 2. Python threads I/O-bo
- Page 1036 and 1037:
Chapter 20 15. CGI errors The Web s
- Page 1038 and 1039:
Chapter 22 1. DB-API The DB-API is
- Page 1040 and 1041:
Appendix B. Reference Tables Python
- Page 1042 and 1043:
Python Standard Operators and Funct
- Page 1044 and 1045:
Numeric Type Operators and Function
- Page 1046 and 1047:
Sequence Type Operators and Functio
- Page 1048 and 1049:
split() • title() • tuple() •
- Page 1050 and 1051:
String Format Operator Directives W
- Page 1052 and 1053:
String Type Built-in Methods The de
- Page 1054 and 1055:
string.title() [b] [c] Returns "tit
- Page 1056 and 1057:
Dictionary Type Built-in Methods In
- Page 1058 and 1059:
Set Types Operators and Functions T
- Page 1060 and 1061:
File Object Methods and Data Attrio
- Page 1062 and 1063:
Python Exceptions Table B.12 lists
- Page 1064 and 1065:
Error [i] UnboundLocalError Access
- Page 1067 and 1068:
Special Methods for Classes Table B
- Page 1069 and 1070:
Numeric Types: base representation
- Page 1071 and 1072:
Python Operator Summary Table B.14
- Page 1073 and 1074:
Appendix 3. About the Author Wesley
- Page 1075 and 1076:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1077 and 1078:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1079 and 1080:
async* module "at-sign" ( @ ) atomi
- Page 1081 and 1082:
uilt-in types 2nd "built-in" names
- Page 1083 and 1084:
uilding applications cgi module coo
- Page 1085 and 1086:
UDP Web 2nd Windows close( ) built-
- Page 1087 and 1088:
cursor (database) cursor objects cu
- Page 1089 and 1090:
function attributes layers in modul
- Page 1091:
distutils package division operator
- Page 1094 and 1095:
equality for sets eric3 errors/erro
- Page 1096 and 1097:
exponentiatial notation output expo
- Page 1098 and 1099:
isatty( ) iterating through 2nd 3rd
- Page 1100 and 1101:
constructs debugging/performance me
- Page 1102 and 1103:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1104 and 1105:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1106 and 1107:
import cycles loading vs. locals( )
- Page 1108 and 1109:
Integrated Development Environments
- Page 1110 and 1111:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1112 and 1113:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1114 and 1115:
loops [See also iterators.] and ite
- Page 1116 and 1117:
epetition 2nd searching vs. 2nd 3rd
- Page 1118 and 1119:
modulefinder modules [See also impo
- Page 1120 and 1121:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1122 and 1123:
complex creating double precision f
- Page 1124 and 1125:
object-oriented language object-ori
- Page 1126 and 1127:
SQLObject 2nd 3rd os module additio
- Page 1128 and 1129:
positional arguments (functions) PO
- Page 1130 and 1131:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1132 and 1133:
any single character ( . ) 2nd ASCI
- Page 1134 and 1135:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1136 and 1137:
elated modules removing set members
- Page 1138 and 1139:
standard files standard input stand
- Page 1140 and 1141:
min( ) no char type for non-NUL/ '0
- Page 1142 and 1143:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1144 and 1145:
truncate( ) built-in method 2nd 3rd
- Page 1146 and 1147:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1149 and 1150:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1151 and 1152:
Web surfing 2nd 3rd while statement
- Page 1153 and 1154:
Index [SYMBOL] [A] [B] [C] [D] [E]
- Page 1155:
Index [SYMBOL] [A] [B] [C] [D] [E]