Pilgrim | Dive Into Python 3 | E-Book | www.sack.de
E-Book

E-Book, Englisch, 403 Seiten

Pilgrim Dive Into Python 3


2. ed
ISBN: 978-1-4302-2416-7
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 403 Seiten

ISBN: 978-1-4302-2416-7
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



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.

Pilgrim Dive Into Python 3 jetzt bestellen!

Autoren/Hrsg.


Weitere Infos & Material


1;Title page;2
2;Copyright Page;3
3;Contents at a Glance;5
4;Table of Contents;6
5;Foreword;14
6;About the Author;16
7;About the Technical Reviewer;17
8;Acknowledgments;18
9;Installing Python;19
9.1;Which Python Is Right for You?;19
9.2;Installing on Microsoft Windows;20
9.3;Installing on Mac OS X;29
9.4;Installing on Ubuntu Linux;41
9.5;Installing on Other Platforms;48
9.6;Using the Python Shell;48
9.7;Python Editors and IDEs;50
9.8;CHAPTER 1 Your First Python Program;52
9.8.1;Declaring Functions;53
9.8.2;Optional and Named Arguments;54
9.8.3;Writing Readable Code;56
9.8.4;Documentation Strings;56
9.8.5;The import Search Path;57
9.8.6;Everything Is an Object;58
9.8.7;What’s an Object?;59
9.8.8;Indenting Code;59
9.8.9;Exceptions;60
9.8.10;Catching Import Errors;62
9.8.11;Unbound Variables;63
9.8.12;Running Scripts;63
9.8.13;Further Reading Online;64
9.9;CHAPTER 2 Native Datatypes;65
9.9.1;Booleans;65
9.9.2;Numbers;66
9.9.3;Coercing Integers to Floats and Vice Versa;67
9.9.3.1;Common Numerical Operations;68
9.9.4;Fractions;69
9.9.5;Trigonometry;70
9.9.6;Numbers in a Boolean Context;70
9.9.7;Lists;71
9.9.7.1;Creating a List;71
9.9.7.2;Slicing a List;72
9.9.7.3;Adding Items to a List;73
9.9.7.4;Searching For Values in a List;75
9.9.7.5;Removing Items from a List;76
9.9.7.6;Removing Items from a List: Bonus Round;76
9.9.7.7;Lists in a Boolean Context;77
9.9.8;Tuples;78
9.9.8.1;Tuples in a Boolean Context;80
9.9.8.2;Assigning Multiple Values at Once;80
9.9.9;Sets;81
9.9.9.1;Modifying a Set;83
9.9.9.2;Removing Items from a Set;84
9.9.9.3;Common Set Operations;85
9.9.9.4;Sets in a Boolean Context;87
9.9.10;Dictionaries;88
9.9.10.1;Creating a Dictionary;88
9.9.10.2;Modifying a Dictionary;88
9.9.10.3;Mixed-Value Dictionaries;89
9.9.10.4;Dictionaries in a Boolean Context;90
9.9.11;None;91
9.9.11.1;None in a Boolean Context;91
9.9.12;Further Reading Online;92
9.10;CHAPTER 3 Comprehensions;93
9.10.1;Working With Files and Directories;93
9.10.1.1;The Current Working Directory;93
9.10.1.2;Working with Filenames and Directory Names;94
9.10.1.3;Listing Directories;96
9.10.1.4;Getting File Metadata;97
9.10.1.5;Constructing Absolute Pathnames;97
9.10.2;List Comprehensions;98
9.10.3;Dictionary Comprehensions;100
9.10.3.1;Fun with Dictionary Comprehensions;101
9.10.4;Set Comprehensions;101
9.10.5;Further Reading Online;102
9.11;CHAPTER 4 Strings;103
9.11.1;Unicode;104
9.11.2;Diving In;106
9.11.3;Formatting Strings;106
9.11.4;Compound Field Names;107
9.11.5;Format Specifiers;109
9.11.6;Other Common String Methods;110
9.11.7;Slicing a String;111
9.11.8;Strings versus Bytes;112
9.11.9;Character Encoding of Python Source Code;115
9.11.10;Further Reading Online;116
9.12;CHAPTER 5 Regular Expressions;118
9.12.1;Case Study: Street Addresses;118
9.12.2;Case Study: Roman Numerals;120
9.12.3;Checking for Thousands;121
9.12.4;Checking for Hundreds;122
9.12.5;Using the {n,m} Syntax;124
9.12.6;Checking for Tens and Ones;125
9.12.7;Verbose Regular Expressions;127
9.12.8;Case Study: Parsing Phone Numbers;129
9.12.9;Further Reading Online;134
9.13;CHAPTER 6 Closures and Generators;135
9.13.1;I Know, Let’s Use Regular Expressions!;136
9.13.2;A List of Functions;138
9.13.3;A List of Patterns;140
9.13.4;A File of Patterns;143
9.13.5;Generators;144
9.13.6;A Fibonacci Generator;146
9.13.7;A Plural Rule Generator;147
9.13.8;Further Reading Online;148
9.14;CHAPTER 7 Classes and Iterators;149
9.14.1;Defining Classes;150
9.14.2;The __init__() Method;150
9.14.3;Instantiating Classes;151
9.14.4;Instance Variables;152
9.14.5;A Fibonacci Iterator;153
9.14.6;A Plural Rule Iterator;155
9.14.7;Further Reading Online;160
9.15;CHAPTER 8 Advanced Iterators;161
9.15.1;Finding All Occurrences of a Pattern;163
9.15.2;Finding the Unique Items in a Sequence;163
9.15.3;Making Assertions;165
9.15.4;Generator Expressions;165
9.15.5;Calculating Permutations … the Lazy Way;167
9.15.6;Other Fun Stuff in the itertools Module;168
9.15.7;A New Kind of String Manipulation;172
9.15.8;Evaluating Arbitrary Strings as Python Expressions;174
9.15.9;Putting It All Together;178
9.15.10;Further Reading Online;178
9.16;CHAPTER 9 Unit Testing;179
9.16.1;A Single Question;180
9.16.2;Halt and Catch Fire;186
9.16.3;More Halting, More Fire;189
9.16.4;And One More Thing …;192
9.16.5;A Pleasing Symmetry;194
9.16.6;More Bad Input;198
9.17;CHAPTER 10 Refactoring;202
9.17.1;Handling Changing Requirements;205
9.17.2;Refactoring;209
9.17.3;Further Reading Online;213
9.18;CHAPTER 11 Files;214
9.18.1;Reading from Text Files;214
9.18.1.1;Character Encoding Rears Its Ugly Head;215
9.18.1.2;Stream Objects;216
9.18.1.3;Reading Data from a Text File;217
9.18.1.4;Closing Files;219
9.18.1.5;Closing Files Automatically;220
9.18.1.6;Reading Data One Line at a Time;220
9.18.2;Writing to Text Files;222
9.18.2.1;Character Encoding Again;223
9.18.3;Binary Files;224
9.18.4;Streams Objects from Nonfile Sources;225
9.18.4.1;Handling Compressed Files;226
9.18.5;Standard Input, Output, and Error;227
9.18.5.1;Redirecting Standard Output;228
9.18.6;Further Reading Online;231
9.19;CHAPTER 12 XML;232
9.19.1;A 5-Minute Crash Course in XML;233
9.19.2;The Structure of an Atom Feed;236
9.19.3;Parsing XML;238
9.19.4;Elements Are Lists;239
9.19.5;Attributes Are Dictionaries;240
9.19.6;Searching for Nodes Within an XML Document;241
9.19.7;Going Further with lxml;244
9.19.8;Generating XML;246
9.19.9;Parsing Broken XML;249
9.19.10;Further Reading Online;251
9.20;CHAPTER 13 Serializing Python Objects;252
9.20.1;A Quick Note About the Examples in this Chapter;252
9.20.2;Saving Data to a Pickle File;253
9.20.3;Loading Data from a Pickle File;255
9.20.4;Pickling Without a File;256
9.20.5;Bytes and Strings Rear Their Ugly Heads Again;257
9.20.6;Debugging Pickle Files;257
9.20.7;Serializing Python Objects to be Read by Other Languages;260
9.20.8;Saving Data to a JSON File;260
9.20.9;Mapping Python Datatypes to JSON;262
9.20.10;Serializing Datatypes Unsupported by JSON;262
9.20.11;Loading Data from a JSON File;267
9.20.12;Further Reading Online;269
9.21;CHAPTER 14 HTTP Web Services;271
9.21.1;Features of HTTP;272
9.21.1.1;Caching;272
9.21.1.2;Last-Modified Checking;273
9.21.1.3;ETags;274
9.21.1.4;Compression;275
9.21.1.5;Redirects;275
9.21.2;How Not to Fetch Data Over HTTP;276
9.21.3;What’s On the Wire?;277
9.21.4;Introducing httplib2;280
9.21.4.1;Caching with httplib2;283
9.21.4.2;Handling Last-Modified and ETag Headers with httplib2;286
9.21.4.3;Handling Compression with httplib2;288
9.21.4.4;Handling Redirects with httplib2;289
9.21.5;Beyond HTTP GET;292
9.21.6;Beyond HTTP POST;296
9.21.7;Further Reading Online;298
9.22;CHAPTER 15 Case Study: Porting chardet to Python 3;299
9.22.1;What Is Character Encoding Auto-Detection?;299
9.22.1.1;Why Auto-Detection Is Difficult;299
9.22.1.2;Auto-Encoding Algorithms;300
9.22.2;Introducing the chardet Module;300
9.22.2.1;UTF-n with a BOM;300
9.22.2.2;Escaped Encodings;300
9.22.2.3;Multibyte Encodings;301
9.22.2.4;Single-Byte Encodings;301
9.22.2.5;windows-1252;302
9.22.3;Running 2to3;302
9.22.4;A Short Digression Into Multi-File Modules;305
9.22.5;Fixing What 2to3 Can’t;307
9.22.5.1;False Is Invalid Syntax;307
9.22.5.2;No Module Named Constants;308
9.22.5.3;Name 'file' Is Not Defined;309
9.22.5.4;Can’t Use a String Pattern on a Bytes-Like Object;310
9.22.5.5;Can’t Convert 'bytes' Object to str Implicitly;312
9.22.5.6;Unsupported Operand type(s) for +: 'int' and 'bytes';315
9.22.5.7;ord() Expected String of Length 1, but int Found;316
9.22.5.8;Unorderable Types: int() >= str();319
9.22.5.9;Global Name 'reduce' Is not Defined;321
9.22.6;Lessons Learned;323
9.23;CHAPTER 16 Packaging Python Libraries;324
9.23.1;Things Distutils Can’t Do for You;325
9.23.2;Directory Structure;326
9.23.2.1;Writing Your Setup Script;327
9.23.3;Classifying Your Package;329
9.23.3.1;Examples of Good Package Classifiers;329
9.23.4;Checking Your Setup Script for Errors;332
9.23.5;Creating a Source Distribution;332
9.23.6;Creating a Graphical Installer;334
9.23.6.1;Building Installable Packages for Other Operating Systems;335
9.23.7;Adding Your Software to the Python Package Index;336
9.23.8;The Many Possible Futures of Python Packaging;337
9.23.9;Further Reading Online;338
9.24;APPENDIX A Porting Code to Python 3 with 2to3;339
9.24.1;print Statement;339
9.24.2;Unicode String Literals;340
9.24.3;unicode() Global Function;340
9.24.4;long Datatype;341
9.24.5;<> Comparison;341
9.24.6;has_key() Dictionary Method;342
9.24.7;Dictionary Methods that Return Lists;343
9.24.8;Renamed or Reorganized Modules;343
9.24.8.1;http;344
9.24.8.2;urllib;344
9.24.8.3;dbm;345
9.24.8.4;xmlrpc;346
9.24.8.5;Other Modules;346
9.24.9;Relative Imports Within a Package;348
9.24.10;next() Iterator Method;349
9.24.11;filter() Global Function;350
9.24.12;map() Global Function;350
9.24.13;reduce() Global Function;351
9.24.14;apply() Global Function;352
9.24.15;intern() Global Function;352
9.24.16;exec Statement;353
9.24.17;execfile Statement;353
9.24.18;repr Literals (Backticks);354
9.24.19;try...except Statement;354
9.24.20;raise Statement;356
9.24.21;throw Method on Generators;356
9.24.22;xrange() Global Function;357
9.24.23;raw_input() and input() Global Functions;358
9.24.24;func_* Function Attributes;358
9.24.25;xreadlines() I/O Method;359
9.24.26;lambda Functions that Take a Tuple Instead of Multiple Parameters;360
9.24.27;Special Method Attributes;361
9.24.28;__nonzero__ Special Method;361
9.24.29;Octal Literals;362
9.24.30;sys.maxint;362
9.24.31;callable() Global Function;363
9.24.32;zip() Global Function;363
9.24.33;StandardError Exception;363
9.24.34;types Module Constants;364
9.24.35;isinstance() Global Function;365
9.24.36;basestring Datatype;365
9.24.37;itertools Module;366
9.24.38;sys.exc_type, sys.exc_value, sys.exc_traceback;366
9.24.39;List Comprehensions Over Tuples;367
9.24.40;os.getcwdu() Function;367
9.24.41;Metaclasses;367
9.24.42;Matters of Style;368
9.24.42.1;set() Literals (Explicit);368
9.24.42.2;buffer() Global Function (Explicit);368
9.24.42.3;Whitespace Around Commas (Explicit);369
9.24.42.4;Common Idioms (Explicit);369
9.25;APPENDIX B Special Method Names;371
9.25.1;Basics;371
9.25.2;Classes that Act Like Iterators;372
9.25.3;Computed Attributes;372
9.25.4;Classes that Act Like Functions;375
9.25.5;Classes that Act Like Sequences;376
9.25.6;Classes that Act Like Dictionaries;378
9.25.7;Classes that Act Like Numbers;379
9.25.8;Classes that Can Be Compared;383
9.25.9;Classes that Can Be Serialized;384
9.25.10;Classes that Can Be Used in a “with” Block;384
9.25.11;Really Esoteric Stuff;386
9.25.12;Further Reading Online;387
9.26;APPENDIX C Where to Go From Here;388
9.27;Index;390



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.