Nicht aus der Schweiz? Besuchen Sie lehmanns.de
Dive Into Python 3 - Mark Pilgrim

Dive Into Python 3 (eBook)

(Autor)

eBook Download: PDF
2010 | 2., Second Edition
412 Seiten
Apress (Verlag)
978-1-4302-2416-7 (ISBN)
Systemvoraussetzungen
66,99 inkl. MwSt
(CHF 65,45)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Mark Pilgrim's Dive Into Python 3 is a hands-on guide to Python 3 and its differences from Python 2. As in the original book, Dive Into Python, each chapter starts with a real, complete code sample, proceeds to pick it apart and explain the pieces, and then puts it all back together in a summary at the end.

This book includes:

  • Example programs completely rewritten to illustrate powerful new concepts now available in Python 3: sets, iterators, generators, closures, comprehensions, and much more
  • A detailed case study of porting a major library from Python 2 to Python 3
  • A comprehensive appendix of all the syntactic and semantic changes in Python 3

This is the perfect resource for you if you need to port applications to Python 3, or if you like to jump into languages fast and get going right away.



By day, Mark Pilgrim is a developer advocate for open source and open standards. By night, he is a husband and father who lives in North Carolina with his wife, his two sons, and his big slobbery dog. He spends his copious free time sunbathing, skydiving, and making up autobiographical information.
Mark Pilgrim's Dive Into Python 3 is a hands-on guide to Python 3 and its differences from Python 2. As in the original book, Dive Into Python, each chapter starts with a real, complete code sample, proceeds to pick it apart and explain the pieces, and then puts it all back together in a summary at the end. This book includes: Example programs completely rewritten to illustrate powerful new concepts now available in Python 3: sets, iterators, generators, closures, comprehensions, and much more A detailed case study of porting a major library from Python 2 to Python 3 A comprehensive appendix of all the syntactic and semantic changes in Python 3 This is the perfect resource for you if you need to port applications to Python 3, or if you like to jump into languages fast and get going right away.

By day, Mark Pilgrim is a developer advocate for open source and open standards. By night, he is a husband and father who lives in North Carolina with his wife, his two sons, and his big slobbery dog. He spends his copious free time sunbathing, skydiving, and making up autobiographical information.

Title page 2
Copyright Page 3
Contents at a Glance 5
Table of Contents 6
Foreword 14
About the Author 16
About the Technical Reviewer 17
Acknowledgments 18
Installing Python 19
Which Python Is Right for You? 19
Installing on Microsoft Windows 20
Installing on Mac OS X 29
Installing on Ubuntu Linux 41
Installing on Other Platforms 48
Using the Python Shell 48
Python Editors and IDEs 50
CHAPTER 1 Your First Python Program 52
Declaring Functions 53
Optional and Named Arguments 54
Writing Readable Code 56
Documentation Strings 56
The import Search Path 57
Everything Is an Object 58
What’s an Object? 59
Indenting Code 59
Exceptions 60
Catching Import Errors 62
Unbound Variables 63
Running Scripts 63
Further Reading Online 64
CHAPTER 2 Native Datatypes 65
Booleans 65
Numbers 66
Coercing Integers to Floats and Vice Versa 67
Common Numerical Operations 68
Fractions 69
Trigonometry 70
Numbers in a Boolean Context 70
Lists 71
Creating a List 71
Slicing a List 72
Adding Items to a List 73
Searching For Values in a List 75
Removing Items from a List 76
Removing Items from a List: Bonus Round 76
Lists in a Boolean Context 77
Tuples 78
Tuples in a Boolean Context 80
Assigning Multiple Values at Once 80
Sets 81
Modifying a Set 83
Removing Items from a Set 84
Common Set Operations 85
Sets in a Boolean Context 87
Dictionaries 88
Creating a Dictionary 88
Modifying a Dictionary 88
Mixed-Value Dictionaries 89
Dictionaries in a Boolean Context 90
None 91
None in a Boolean Context 91
Further Reading Online 92
CHAPTER 3 Comprehensions 93
Working With Files and Directories 93
The Current Working Directory 93
Working with Filenames and Directory Names 94
Listing Directories 96
Getting File Metadata 97
Constructing Absolute Pathnames 97
List Comprehensions 98
Dictionary Comprehensions 100
Fun with Dictionary Comprehensions 101
Set Comprehensions 101
Further Reading Online 102
CHAPTER 4 Strings 103
Unicode 104
Diving In 106
Formatting Strings 106
Compound Field Names 107
Format Specifiers 109
Other Common String Methods 110
Slicing a String 111
Strings versus Bytes 112
Character Encoding of Python Source Code 115
Further Reading Online 116
CHAPTER 5 Regular Expressions 118
Case Study: Street Addresses 118
Case Study: Roman Numerals 120
Checking for Thousands 121
Checking for Hundreds 122
Using the {n,m} Syntax 124
Checking for Tens and Ones 125
Verbose Regular Expressions 127
Case Study: Parsing Phone Numbers 129
Further Reading Online 134
CHAPTER 6 Closures and Generators 135
I Know, Let’s Use Regular Expressions! 136
A List of Functions 138
A List of Patterns 140
A File of Patterns 143
Generators 144
A Fibonacci Generator 146
A Plural Rule Generator 147
Further Reading Online 148
CHAPTER 7 Classes and Iterators 149
Defining Classes 150
The __init__() Method 150
Instantiating Classes 151
Instance Variables 152
A Fibonacci Iterator 153
A Plural Rule Iterator 155
Further Reading Online 160
CHAPTER 8 Advanced Iterators 161
Finding All Occurrences of a Pattern 163
Finding the Unique Items in a Sequence 163
Making Assertions 165
Generator Expressions 165
Calculating Permutations … the Lazy Way 167
Other Fun Stuff in the itertools Module 168
A New Kind of String Manipulation 172
Evaluating Arbitrary Strings as Python Expressions 174
Putting It All Together 178
Further Reading Online 178
CHAPTER 9 Unit Testing 179
A Single Question 180
Halt and Catch Fire 186
More Halting, More Fire 189
And One More Thing … 192
A Pleasing Symmetry 194
More Bad Input 198
CHAPTER 10 Refactoring 202
Handling Changing Requirements 205
Refactoring 209
Further Reading Online 213
CHAPTER 11 Files 214
Reading from Text Files 214
Character Encoding Rears Its Ugly Head 215
Stream Objects 216
Reading Data from a Text File 217
Closing Files 219
Closing Files Automatically 220
Reading Data One Line at a Time 220
Writing to Text Files 222
Character Encoding Again 223
Binary Files 224
Streams Objects from Nonfile Sources 225
Handling Compressed Files 226
Standard Input, Output, and Error 227
Redirecting Standard Output 228
Further Reading Online 231
CHAPTER 12 XML 232
A 5-Minute Crash Course in XML 233
The Structure of an Atom Feed 236
Parsing XML 238
Elements Are Lists 239
Attributes Are Dictionaries 240
Searching for Nodes Within an XML Document 241
Going Further with lxml 244
Generating XML 246
Parsing Broken XML 249
Further Reading Online 251
CHAPTER 13 Serializing Python Objects 252
A Quick Note About the Examples in this Chapter 252
Saving Data to a Pickle File 253
Loading Data from a Pickle File 255
Pickling Without a File 256
Bytes and Strings Rear Their Ugly Heads Again 257
Debugging Pickle Files 257
Serializing Python Objects to be Read by Other Languages 260
Saving Data to a JSON File 260
Mapping Python Datatypes to JSON 262
Serializing Datatypes Unsupported by JSON 262
Loading Data from a JSON File 267
Further Reading Online 269
CHAPTER 14 HTTP Web Services 271
Features of HTTP 272
Caching 272
Last-Modified Checking 273
ETags 274
Compression 275
Redirects 275
How Not to Fetch Data Over HTTP 276
What’s On the Wire? 277
Introducing httplib2 280
Caching with httplib2 283
Handling Last-Modified and ETag Headers with httplib2 286
Handling Compression with httplib2 288
Handling Redirects with httplib2 289
Beyond HTTP GET 292
Beyond HTTP POST 296
Further Reading Online 298
CHAPTER 15 Case Study: Porting chardet to Python 3 299
What Is Character Encoding Auto-Detection? 299
Why Auto-Detection Is Difficult 299
Auto-Encoding Algorithms 300
Introducing the chardet Module 300
UTF-n with a BOM 300
Escaped Encodings 300
Multibyte Encodings 301
Single-Byte Encodings 301
windows-1252 302
Running 2to3 302
A Short Digression Into Multi-File Modules 305
Fixing What 2to3 Can’t 307
False Is Invalid Syntax 307
No Module Named Constants 308
Name 'file' Is Not Defined 309
Can’t Use a String Pattern on a Bytes-Like Object 310
Can’t Convert 'bytes' Object to str Implicitly 312
Unsupported Operand type(s) for +: 'int' and 'bytes' 315
ord() Expected String of Length 1, but int Found 316
Unorderable Types: int() > = str()
Global Name 'reduce' Is not Defined 321
Lessons Learned 323
CHAPTER 16 Packaging Python Libraries 324
Things Distutils Can’t Do for You 325
Directory Structure 326
Writing Your Setup Script 327
Classifying Your Package 329
Examples of Good Package Classifiers 329
Checking Your Setup Script for Errors 332
Creating a Source Distribution 332
Creating a Graphical Installer 334
Building Installable Packages for Other Operating Systems 335
Adding Your Software to the Python Package Index 336
The Many Possible Futures of Python Packaging 337
Further Reading Online 338
APPENDIX A Porting Code to Python 3 with 2to3 339
print Statement 339
Unicode String Literals 340
unicode() Global Function 340
long Datatype 341
< >
has_key() Dictionary Method 342
Dictionary Methods that Return Lists 343
Renamed or Reorganized Modules 343
http 344
urllib 344
dbm 345
xmlrpc 346
Other Modules 346
Relative Imports Within a Package 348
next() Iterator Method 349
filter() Global Function 350
map() Global Function 350
reduce() Global Function 351
apply() Global Function 352
intern() Global Function 352
exec Statement 353
execfile Statement 353
repr Literals (Backticks) 354
try...except Statement 354
raise Statement 356
throw Method on Generators 356
xrange() Global Function 357
raw_input() and input() Global Functions 358
func_* Function Attributes 358
xreadlines() I/O Method 359
lambda Functions that Take a Tuple Instead of Multiple Parameters 360
Special Method Attributes 361
__nonzero__ Special Method 361
Octal Literals 362
sys.maxint 362
callable() Global Function 363
zip() Global Function 363
StandardError Exception 363
types Module Constants 364
isinstance() Global Function 365
basestring Datatype 365
itertools Module 366
sys.exc_type, sys.exc_value, sys.exc_traceback 366
List Comprehensions Over Tuples 367
os.getcwdu() Function 367
Metaclasses 367
Matters of Style 368
set() Literals (Explicit) 368
buffer() Global Function (Explicit) 368
Whitespace Around Commas (Explicit) 369
Common Idioms (Explicit) 369
APPENDIX B Special Method Names 371
Basics 371
Classes that Act Like Iterators 372
Computed Attributes 372
Classes that Act Like Functions 375
Classes that Act Like Sequences 376
Classes that Act Like Dictionaries 378
Classes that Act Like Numbers 379
Classes that Can Be Compared 383
Classes that Can Be Serialized 384
Classes that Can Be Used in a “with” Block 384
Really Esoteric Stuff 386
Further Reading Online 387
APPENDIX C Where to Go From Here 388
Index 390

Erscheint lt. Verlag 10.3.2010
Zusatzinfo 412 p.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Python
Mathematik / Informatik Informatik Theorie / Studium
Mathematik / Informatik Informatik Web / Internet
Schlagworte HTML • Performance • Processing • programming • Web Services • XML
ISBN-10 1-4302-2416-9 / 1430224169
ISBN-13 978-1-4302-2416-7 / 9781430224167
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 3,0 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
ein kompakter Einstieg für die Praxis

von Ralph Steyer

eBook Download (2024)
Springer Vieweg (Verlag)
CHF 34,15
Arbeiten mit NumPy, Matplotlib und Pandas

von Bernd Klein

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
CHF 29,30