Dive Into Python 3 (Books for Professionals by Professionals)

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The print quality of this book is awful. My copy looks like it was printed on a cheap inkjet printer. The print is tiny. Really tiny. And the top and bottom margins are 1-3/8" each! Seriously, is this a joke? This book probably has some great content, but the print quality is so bad it's worthless.

Author(s): Mark Pilgrim
Series: Books for Professionals by Professionals
Edition: 2
Publisher: Apress
Year: 2009

Language: English
Commentary: +OCR
Pages: 489

a.k.a. “the minus level”......Page 1
Which Python Is Right For You?......Page 3
Installing on Microsoft Windows......Page 4
Installing on Mac OS X......Page 12
Installing on Ubuntu Linux......Page 22
Using The Python Shell......Page 29
Python Editors and IDEs......Page 33
Diving In......Page 34
Declaring Functions......Page 36
Optional and Named Arguments......Page 38
Documentation Strings......Page 40
The import Search Path......Page 41
Everything Is An Object......Page 43
What’s An Object?......Page 44
Indenting Code......Page 45
Exceptions......Page 46
Catching Import Errors......Page 48
Unbound Variables......Page 49
Everything is Case-Sensitive......Page 50
Running Scripts......Page 51
Further Reading......Page 52
Diving In......Page 53
Booleans......Page 54
Coercing Integers To Floats And Vice-Versa......Page 56
Common Numerical Operations......Page 57
Trigonometry......Page 59
Numbers In A Boolean Context......Page 60
Creating A List......Page 62
Slicing A List......Page 63
Adding Items To A List......Page 64
Searching For Values In A List......Page 67
Removing Items From A List......Page 68
Removing Items From A List: Bonus Round......Page 69
Tuples......Page 71
Tuples In A Boolean Context......Page 74
Assigning Multiple Values At Once......Page 75
Creating A Set......Page 76
Modifying A Set......Page 78
Removing Items From A Set......Page 79
Common Set Operations......Page 81
Sets In A Boolean Context......Page 84
Creating A Dictionary......Page 85
Modifying A Dictionary......Page 86
Mixed-Value Dictionaries......Page 87
None......Page 89
None In A Boolean Context......Page 90
Further Reading......Page 91
The Current Working Directory......Page 92
Working With Filenames and Directory Names......Page 94
Listing Directories......Page 96
Getting File Metadata......Page 98
Constructing Absolute Pathnames......Page 99
List Comprehensions......Page 100
Dictionary Comprehensions......Page 102
Other Fun Stuff To Do With Dictionary Comprehensions......Page 104
Set Comprehensions......Page 105
Further Reading......Page 106
Some Boring Stuff You Need To Understand Before You Can Dive In......Page 107
Unicode......Page 109
Diving In......Page 112
Formatting Strings......Page 113
Compound Field Names......Page 116
Format Specifiers......Page 118
Other Common String Methods......Page 119
Slicing A String......Page 121
Strings vs. Bytes......Page 122
Postscript: Character Encoding Of Python Source Code......Page 126
Further Reading......Page 127
Diving In......Page 128
Case Study: Street Addresses......Page 129
Case Study: Roman Numerals......Page 131
Checking For Thousands......Page 133
Checking For Hundreds......Page 134
Using The {n,m} Syntax......Page 136
Checking For Tens And Ones......Page 137
Verbose Regular Expressions......Page 140
Case study: Parsing Phone Numbers......Page 142
Summary......Page 149
Diving In......Page 151
I Know, Let’s Use Regular Expressions!......Page 152
A List Of Functions......Page 156
A List Of Patterns......Page 160
A File Of Patterns......Page 162
Generators......Page 164
A Fibonacci Generator......Page 166
A Plural Rule Generator......Page 167
Further Reading......Page 169
Diving In......Page 170
Defining Classes......Page 171
The __init__() Method......Page 172
Instantiating Classes......Page 173
Instance Variables......Page 174
A Fibonacci Iterator......Page 175
A Plural Rule Iterator......Page 178
Further Reading......Page 185
Diving In......Page 187
Finding all occurrences of a pattern......Page 190
Finding the unique items in a sequence......Page 191
Making assertions......Page 193
Generator expressions......Page 194
Calculating Permutations… The Lazy Way!......Page 195
Other Fun Stuff in the itertools Module......Page 198
A New Kind Of String Manipulation......Page 203
Evaluating Arbitrary Strings As Python Expressions......Page 205
Putting It All Together......Page 210
Further Reading......Page 211
Not) Diving In......Page 212
A Single Question......Page 214
“Halt And Catch Fire”......Page 222
More Halting, More Fire......Page 227
And One More Thing…......Page 231
A Pleasing Symmetry......Page 235
More Bad Input......Page 241
Diving In......Page 246
Handling Changing Requirements......Page 250
Refactoring......Page 257
Summary......Page 263
Reading From Text Files......Page 264
Character Encoding Rears Its Ugly Head......Page 265
Stream Objects......Page 266
Reading Data From A Text File......Page 267
Closing Files......Page 270
Closing Files Automatically......Page 271
Reading Data One Line At A Time......Page 272
Writing to Text Files......Page 274
Binary Files......Page 276
Stream Objects From Non-File Sources......Page 278
Handling Compressed Files......Page 280
Standard Input, Output, and Error......Page 282
Redirecting Standard Output......Page 283
Further Reading......Page 287
Diving In......Page 288
A 5-Minute Crash Course in XML......Page 291
The Structure Of An Atom Feed......Page 293
Parsing XML......Page 296
Elements Are Lists......Page 297
Attributes Are Dictonaries......Page 298
Searching For Nodes Within An XML Document......Page 299
Going Further With lxml......Page 303
Generating XML......Page 306
Parsing Broken XML......Page 309
Further Reading......Page 311
Diving In......Page 312
Saving Data to a Pickle File......Page 313
Loading Data from a Pickle File......Page 315
Pickling Without a File......Page 317
Bytes and Strings Rear Their Ugly Heads Again......Page 318
Debugging Pickle Files......Page 319
Serializing Python Objects to be Read by Other Languages......Page 322
Saving Data to a JSON File......Page 323
Mapping of Python Datatypes to JSON......Page 325
Serializing Datatypes Unsupported by JSON......Page 326
Loading Data from a JSON File......Page 331
Further Reading......Page 335
Diving In......Page 337
Caching......Page 338
Last-Modified Checking......Page 340
ETag Checking......Page 342
Redirects......Page 344
How Not To Fetch Data Over HTTP......Page 346
What’s On The Wire?......Page 347
Introducing httplib2......Page 352
A Short Digression To Explain Why httplib2 Returns Bytes Instead of Strings......Page 356
How httplib2 Handles Caching......Page 357
How httplib2 Handles Last-Modified and ETag Headers......Page 361
How http2lib Handles Compression......Page 364
How httplib2 Handles Redirects......Page 365
Beyond HTTP GET......Page 371
Beyond HTTP POST......Page 377
Further Reading......Page 379
Diving In......Page 381
Introducing The chardet Module......Page 382
UTF-n With A BOM......Page 383
Multi-Byte Encodings......Page 384
Single-Byte Encodings......Page 385
Running 2to3......Page 386
A Short Digression Into Multi-File Modules......Page 392
False is invalid syntax......Page 394
No module named constants......Page 395
Can’t use a string pattern on a bytes-like object......Page 397
Can't convert 'bytes' object to str implicitly......Page 401
Unsupported operand type(s) for +: 'int' and 'bytes'......Page 405
ord() expected string of length 1, but int found......Page 407
Unorderable types: int() >= str()......Page 410
Global name 'reduce' is not defined......Page 414
Summary......Page 418
Diving In......Page 419
Things Distutils Can’t Do For You......Page 421
Directory Structure......Page 422
Writing Your Setup Script......Page 424
Classifying Your Package......Page 425
Examples of Good Package Classifiers......Page 426
Specifying Additional Files With A Manifest......Page 428
Checking Your Setup Script for Errors......Page 429
Creating a Source Distribution......Page 430
Creating a Graphical Installer......Page 433
Building Installable Packages for Other Operating Systems......Page 435
Adding Your Software to The Python Package Index......Page 436
The Many Possible Futures of Python Packaging......Page 438
Further Reading......Page 439
print statement......Page 440
unicode() global function......Page 441
<> comparison......Page 442
Dictionary methods that return lists......Page 443
http......Page 444
urllib......Page 445
dbm......Page 446
Other modules......Page 447
Relative imports within a package......Page 448
next() iterator method......Page 449
filter() global function......Page 450
reduce() global function......Page 451
intern() global function......Page 452
execfile statement......Page 453
try...except statement......Page 454
raise statement......Page 455
xrange() global function......Page 456
raw_input() and input() global functions......Page 457
xreadlines() I/O method......Page 458
lambda functions that take a tuple instead of multiple parameters......Page 459
__nonzero__ special method......Page 460
callable() global function......Page 461
types module constants......Page 462
isinstance() global function......Page 463
itertools module......Page 464
os.getcwdu() function......Page 465
set() literals (explicit)......Page 466
Whitespace around commas (explicit)......Page 467
Common idioms (explicit)......Page 468
Basics......Page 469
Classes That Act Like Iterators......Page 470
Computed Attributes......Page 471
Classes That Act Like Functions......Page 474
Classes That Act Like Sequences......Page 476
Classes That Act Like Dictionaries......Page 477
Classes That Act Like Numbers......Page 479
Classes That Can Be Compared......Page 482
Classes That Can Be Serialized......Page 483
Classes That Can Be Used in a with Block......Page 484
Further Reading......Page 486
Things to Read......Page 488
Where To Look For Python 3-Compatible Code......Page 489