E-Book, Englisch, 368 Seiten
Alchin Pro Python
1. ed
ISBN: 978-1-4302-2758-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 368 Seiten
ISBN: 978-1-4302-2758-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
You?ve learned the basics of Python, but how do you take your skills to the next stage? Even if you know enough to be productive, there are a number of features that can take you to the next level in Python. Pro Python explores concepts and features normally left to experimentation, allowing you to be even more productive and creative. In addition to pure code concerns, Pro Python will develop your programming techniques and approaches, which will help make you a better Python programmer. Not only will this book help your code, it will also help you understand and interact with the many established Python communities, or even start your own. Take your Python knowledge and coding skills to the next level. Write clean, innovative code that will be respected among your peers. Make your code do more with introspection and metaprogramming. Design complete frameworks and libraries (two are included in the book!). For more information, including a link to the source code referenced in the book, please visit http://propython.com/.
By day, Marty Alchin works as a senior software engineer at Heroku, and after that, he writes and codes for fun and community. His blog can be found at http://martyalchin.com/ and he has profiles on many other services under the name Gulopine. In particular, his code can be found on GitHub and his random thoughts are on Twitter. He also accepts tips for his open source work at https://gittip.com/gulopine.
Autoren/Hrsg.
Weitere Infos & Material
1;Title Page;1
2;Copyright Page;2
3;Contents at a Glance;3
4;Table of Contents;4
5;About the Author;16
6;About the Technical Reviewer;17
7;Acknowledgments;18
8;Introduction;19
8.1;Who This Book Is For;19
8.2;What You’ll Need;19
8.3;Source Code;19
9;Chapter 1 Principles and Philosophy;20
9.1;The Zen of Python;20
9.1.1;Beautiful Is Better Than Ugly;21
9.1.2;Explicit Is Better Than Implicit;21
9.1.3;Simple Is Better Than Complex;22
9.1.4;Complex Is Better Than Complicated;22
9.1.5;Flat Is Better Than Nested;23
9.1.6;Sparse Is Better Than Dense;24
9.1.7;Readability Counts;24
9.1.8;Special Cases Aren’t Special Enough to Break the Rules;25
9.1.9;Although Practicality Beats Purity;25
9.1.10;Errors Should Never Pass Silently;26
9.1.11;Unless Explicitly Silenced;27
9.1.12;In the Face of Ambiguity, Refuse the Temptation to Guess;28
9.1.13;There Should Be One—and Preferably Only One— Obvious Way to Do It;29
9.1.14;Although That Way May Not Be Obvious at First Unless You’re Dutch;29
9.1.15;Now Is Better Than Never;30
9.1.16;Although Never Is Often Better Than Right Now;30
9.1.17;If the Implementation is Hard to Explain, It’s a Bad Idea;30
9.1.18;If the Implementation is Easy to Explain, It May Be a Good Idea;30
9.1.19;Namespaces Are One Honking Great Idea— Let’s Do More of Those!;31
9.2;Don’t Repeat Yourself;31
9.3;Loose Coupling;32
9.4;The Samurai Principle;32
9.5;The Pareto Principle;33
9.6;The Robustness Principle;33
9.7;Backward Compatibility;34
9.8;The Road to Python 3.0;35
9.9;Taking It With You;36
10;Chapter 2 Advanced Basics;37
10.1;General Concepts;37
10.1.1;Iteration;37
10.1.2;Caching;38
10.1.3;Transparency;39
10.2;Control Flow;39
10.2.1;Catching Exceptions;39
10.2.2;Exception Chains;42
10.2.3;When Everything Goes Right;44
10.2.4;Proceeding Regardless of Exceptions;45
10.2.5;Optimizing Loops;47
10.2.6;The with Statement;47
10.2.7;Conditional Expressions;49
10.3;Iteration;51
10.3.1;Sequence Unpacking;52
10.3.2;List Comprehensions;53
10.3.3;Generator Expressions;54
10.3.4;Set Comprehensions;55
10.3.5;Dictionary Comprehensions;55
10.3.6;Chaining Iterables Together;56
10.3.7;Zipping Iterables Together;56
10.4;Collections;57
10.4.1;Sets;57
10.4.2;Named Tuples;61
10.4.3;Ordered Dictionaries;62
10.4.4;Dictionaries with Defaults;62
10.5;Importing Code;63
10.5.1;Fallback Imports;63
10.5.2;Importing from the Future;64
10.5.3;Using __all__ to Customize Imports;65
10.5.4;Relative Imports;66
10.5.5;The __import__() function;67
10.5.6;The importlib module;69
10.6;Taking It With You;70
11;Chapter 3 Functions;71
11.1;Arguments;71
11.1.1;Planning for Flexibility;72
11.1.2;Variable Positional Arguments;72
11.1.3;Variable Keyword Arguments;73
11.1.4;Combining Different Kinds of Arguments;74
11.1.5;Invoking Functions with Variable Arguments;77
11.1.6;Preloading Arguments;78
11.1.7;Introspection;79
11.1.8;Example: Identifying Argument Values;80
11.1.9;Example: A More Concise Version;82
11.1.10;Example: Validating Arguments;84
11.2;Decorators;85
11.2.1;Closures;87
11.2.2;Wrappers;89
11.2.3;Decorators with Arguments;90
11.2.4;Decorators with—or without—Arguments;92
11.2.5;Example: Memoization;93
11.2.6;Example: A Decorator to Create Decorators;95
11.3;Function Annotations;96
11.3.1;Example: Type Safety;97
11.3.2;Factoring Out the Boilerplate;104
11.3.3;Example: Type Coercion;106
11.3.4;Annotating with Decorators;108
11.3.5;Example: Type Safety as a Decorator;108
11.4;Generators;112
11.5;Lambdas;114
11.6;Introspection;115
11.6.1;Identifying Object Types;116
11.6.2;Modules and Packages;116
11.6.3;Docstrings;117
11.7;Taking It With You;119
12;Chapter 4 Classes;120
12.1;Inheritance;120
12.1.1;Multiple Inheritance;122
12.1.2;Method Resolution Order (MRO);123
12.1.3;Example: C3 Algorithm;126
12.1.4;Using super() to Pass Control to Other Classes;132
12.1.5;Introspection;134
12.2;How Classes Are Created;136
12.2.1;Creating Classes at Runtime;137
12.2.2;Metaclasses;138
12.2.3;Example: Plugin Framework;139
12.2.4;Controlling the Namespace;142
12.3;Attributes;143
12.3.1;Properties;144
12.3.2;Descriptors;146
12.4;Methods;148
12.4.1;Unbound Methods;148
12.4.2;Bound Methods;149
12.4.3;Class Methods;150
12.4.4;Static Methods;151
12.4.5;Assigning Functions to Classes and Instances;152
12.5;Magic Methods;152
12.5.1;Creating Instances;153
12.5.2;Example: Automatic Subclasses;154
12.5.3;Dealing with Attributes;155
12.5.4;String Representations;157
12.6;Taking It With You;159
13;Chapter 5 Common Protocols;160
13.1;Basic Operations;160
13.1.1;Mathematical Operations;161
13.1.2;Bitwise Operations;165
13.1.3;Variations;167
13.2;Numbers;169
13.2.1;Sign Operations;171
13.2.2;Comparison Operations;171
13.3;Iterables;172
13.3.1;Example: Repeatable Generators;175
13.4;Sequences;176
13.5;Mappings;181
13.6;Callables;182
13.7;Context Managers;183
13.8;Taking It With You;185
14;Chapter 6: Object Management;186
14.1;Namespace Dictionary;187
14.1.1;Example: Borg Pattern;187
14.1.2;Example: Self-caching properties;190
14.2;Garbage Collection;193
14.2.1;Reference Counting;194
14.2.2;Cyclical References;195
14.2.3;Weak References;197
14.3;Pickling;199
14.4;Copying;203
14.4.1;Shallow Copies;204
14.4.2;Deep Copies;205
14.5;Taking It With You;207
15;Chapter 7 Strings;208
15.1;Bytes;208
15.1.1;Simple Conversion: chr() and ord();209
15.1.2;Complex Conversion: The Struct Module;210
15.2;Text;212
15.2.1;Unicode;213
15.2.2;Encodings;213
15.3;Simple Substitution;215
15.4;Formatting;218
15.4.1;Looking Up Values Within Objects;219
15.4.2;Distinguishing Types of Strings;219
15.4.3;Standard Format Specification;220
15.4.4;Example: Plain Text Table of Contents;221
15.4.5;Custom Format Specification;222
15.5;Taking It With You;223
16;Chapter 8 Documentation;224
16.1;Proper Naming;224
16.2;Comments;225
16.3;Docstrings;225
16.3.1;Describe What the Function Does;226
16.3.2;Explain the Arguments;226
16.3.3;Don’t Forget the Return Value;226
16.3.4;Include Any Expected Exceptions;227
16.4;Documentation Outside the Code;227
16.4.1;Installation and Configuration;227
16.4.2;Tutorials;227
16.4.3;Reference Documents;227
16.5;Documentation Utilities;228
16.5.1;Formatting;229
16.5.2;Links;230
16.5.3;Sphinx;231
16.6;Taking It With You;232
17;Chapter 9 Testing;233
17.1;Test-Driven Development (TDD);233
17.2;Doctests;234
17.2.1;Formatting Code;234
17.2.2;Representing Output;234
17.2.3;Integrating With Documentation;235
17.2.4;Running Tests;236
17.3;The unittest module;237
17.3.1;Setting Up;237
17.3.2;Writing Tests;238
17.3.3;Other Comparisons;242
17.3.4;Testing Strings and Other Sequence Content;242
17.3.5;Testing Exceptions;243
17.3.6;Testing Identity;245
17.3.7;Tearing Down;245
17.4;Providing a Custom Test Class;246
17.4.1;Changing Test Behavior;246
17.5;Taking It With You;247
18;Chapter 10 Distribution;248
18.1;Licensing;248
18.1.1;GNU General Public License (GPL);248
18.1.2;Affero General Public License (AGPL);249
18.1.3;GNU Lesser General Public License (LGPL);250
18.1.4;Berkeley Software Distribution (BSD) License;250
18.1.5;Other Licenses;251
18.2;Packaging;251
18.2.1;setup.py;252
18.2.2;MANIFEST.in;254
18.2.3;The sdist command;255
18.3;Distribution;256
18.4;Taking It With You;257
19;Chapter 11 Sheets: A CSV Framework;258
19.1;Building a Declarative Framework;259
19.1.1;Introducing Declarative Programming;259
19.1.2;To Build or Not to Build?;260
19.2;Building the Framework;261
19.2.1;Managing Options;262
19.2.2;Defining Fields;264
19.2.3;Attaching a Field to a Class;265
19.2.4;Adding a Metaclass;267
19.2.5;Bringing It Together;270
19.3;Ordering Fields;271
19.3.1;DeclarativeMeta.__prepare__();271
19.3.2;Column.__init__();273
19.3.3;Column.__new__();276
19.3.4;CounterMeta.__call__();277
19.3.5;Choosing an Option;278
19.4;Building a Field Library;278
19.4.1;StringField;279
19.4.2;IntegerColumn;280
19.4.3;FloatColumn;280
19.4.4;DecimalColumn;280
19.4.5;DateColumn;281
19.5;Getting Back to CSV;285
19.5.1;Checking Arguments;286
19.5.2;Populating Values;288
19.5.3;The Reader;290
19.5.4;The Writer;294
19.6;Taking It With You;296
20;PEP 8 Style Guide for Python;297
20.1;Introduction;297
20.2;A Foolish Consistency is the Hobgoblin of Little Minds;297
20.3;Code Layout;298
20.3.1;Indentation;298
20.3.2;Tabs or Spaces?;298
20.3.3;Maximum Line Length;298
20.3.4;Blank Lines;298
20.3.5;Encodings (PEP 263);299
20.4;Imports;299
20.5;Whitespace in Expressions and Statements;300
20.5.1;Pet Peeves;300
20.5.2;Other Recommendations;301
20.6;Comments;302
20.6.1;Block Comments;303
20.6.2;Inline Comments;303
20.7;Documentation Strings;303
20.8;Version Bookkeeping;304
20.9;Naming Conventions;304
20.9.1;Descriptive: Naming Styles;304
20.9.2;Prescriptive: Naming Conventions;305
20.9.2.1;Names to Avoid;305
20.9.2.2;Package and Module Names;305
20.9.2.3;Class Names;306
20.9.2.4;Exception Names;306
20.9.2.5;Global Variable Names;306
20.9.2.6;Function Names;306
20.9.2.7;Function and Method Arguments;306
20.9.2.8;Method Names and Instance Variables;306
20.9.2.9;Constants;307
20.9.2.10;Designing for Inheritance;307
20.10;Programming Recommendations;308
20.11;Copyright;311
21;PEP 10 Voting Guidelines;312
21.1;Abstract;312
21.2;Rationale;312
21.3;Voting Scores;312
21.4;Copyright;313
22;PEP 20 The Zen of Python;314
22.1;Abstract;314
22.2;The Zen of Python;314
22.3;Easter Egg;314
22.4;Copyright;315
23;PEP 257: Docstring Conventions;316
23.1;Abstract;316
23.2;Rationale;316
23.3;Specification;316
23.3.1;What is a Docstring?;316
23.3.2;One-Line Docstrings;317
23.3.3;Multi-Line Docstrings;318
23.3.4;Handling Docstring Indentation;319
23.4;Copyright;320
23.5;Acknowledgments;320
24;PEP 387 Backwards Compatibility Policy;321
24.1;Abstract;321
24.2;Rationale;321
24.3;Backwards Compatibility Rules;321
24.4;Making Incompatible Changes;322
24.5;Copyright;323
25;PEP 3000 Python 3000;324
25.1;Abstract;324
25.2;Naming;324
25.3;PEP Numbering;324
25.4;Timeline;324
25.5;Compatibility and Transition;325
25.6;Implementation Language;326
25.7;Meta-Contributions;326
25.8;Copyright;326
26;PEP 3003 Python Language Moratorium;327
26.1;Abstract;327
26.2;Rationale;327
26.3;Details;328
26.3.1;Cannot Change;328
26.3.2;Case-by-Case Exemptions;328
26.3.3;Allowed to Change;328
26.4;Retroactive;329
26.5;Extensions;329
26.6;Copyright;329
27;Index;330




