Pro Python (eBook)

(Autor)

eBook Download: PDF
2010 | 1st ed.
368 Seiten
Apress (Verlag)
978-1-4302-2758-8 (ISBN)

Lese- und Medienproben

Pro Python - Marty Alchin
Systemvoraussetzungen
52,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

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.
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.

Title Page 1
Copyright Page 2
Contents at a Glance 3
Table of Contents 4
About the Author 16
About the Technical Reviewer 17
Acknowledgments 18
Introduction 19
Who This Book Is For 19
What You’ll Need 19
Source Code 19
Chapter 1 Principles and Philosophy 20
The Zen of Python 20
Beautiful Is Better Than Ugly 21
Explicit Is Better Than Implicit 21
Simple Is Better Than Complex 22
Complex Is Better Than Complicated 22
Flat Is Better Than Nested 23
Sparse Is Better Than Dense 24
Readability Counts 24
Special Cases Aren’t Special Enough to Break the Rules 25
Although Practicality Beats Purity 25
Errors Should Never Pass Silently 26
Unless Explicitly Silenced 27
In the Face of Ambiguity, Refuse the Temptation to Guess 28
There Should Be One—and Preferably Only One— Obvious Way to Do It 29
Although That Way May Not Be Obvious at First Unless You’re Dutch 29
Now Is Better Than Never 30
Although Never Is Often Better Than Right Now 30
If the Implementation is Hard to Explain, It’s a Bad Idea 30
If the Implementation is Easy to Explain, It May Be a Good Idea 30
Namespaces Are One Honking Great Idea— Let’s Do More of Those! 31
Don’t Repeat Yourself 31
Loose Coupling 32
The Samurai Principle 32
The Pareto Principle 33
The Robustness Principle 33
Backward Compatibility 34
The Road to Python 3.0 35
Taking It With You 36
Chapter 2 Advanced Basics 37
General Concepts 37
Iteration 37
Caching 38
Transparency 39
Control Flow 39
Catching Exceptions 39
Exception Chains 42
When Everything Goes Right 44
Proceeding Regardless of Exceptions 45
Optimizing Loops 47
The with Statement 47
Conditional Expressions 49
Iteration 51
Sequence Unpacking 52
List Comprehensions 53
Generator Expressions 54
Set Comprehensions 55
Dictionary Comprehensions 55
Chaining Iterables Together 56
Zipping Iterables Together 56
Collections 57
Sets 57
Named Tuples 61
Ordered Dictionaries 62
Dictionaries with Defaults 62
Importing Code 63
Fallback Imports 63
Importing from the Future 64
Using __all__ to Customize Imports 65
Relative Imports 66
The __import__() function 67
The importlib module 69
Taking It With You 70
Chapter 3 Functions 71
Arguments 71
Planning for Flexibility 72
Variable Positional Arguments 72
Variable Keyword Arguments 73
Combining Different Kinds of Arguments 74
Invoking Functions with Variable Arguments 77
Preloading Arguments 78
Introspection 79
Example: Identifying Argument Values 80
Example: A More Concise Version 82
Example: Validating Arguments 84
Decorators 85
Closures 87
Wrappers 89
Decorators with Arguments 90
Decorators with—or without—Arguments 92
Example: Memoization 93
Example: A Decorator to Create Decorators 95
Function Annotations 96
Example: Type Safety 97
Factoring Out the Boilerplate 104
Example: Type Coercion 106
Annotating with Decorators 108
Example: Type Safety as a Decorator 108
Generators 112
Lambdas 114
Introspection 115
Identifying Object Types 116
Modules and Packages 116
Docstrings 117
Taking It With You 119
Chapter 4 Classes 120
Inheritance 120
Multiple Inheritance 122
Method Resolution Order (MRO) 123
Example: C3 Algorithm 126
Using super() to Pass Control to Other Classes 132
Introspection 134
How Classes Are Created 136
Creating Classes at Runtime 137
Metaclasses 138
Example: Plugin Framework 139
Controlling the Namespace 142
Attributes 143
Properties 144
Descriptors 146
Methods 148
Unbound Methods 148
Bound Methods 149
Class Methods 150
Static Methods 151
Assigning Functions to Classes and Instances 152
Magic Methods 152
Creating Instances 153
Example: Automatic Subclasses 154
Dealing with Attributes 155
String Representations 157
Taking It With You 159
Chapter 5 Common Protocols 160
Basic Operations 160
Mathematical Operations 161
Bitwise Operations 165
Variations 167
Numbers 169
Sign Operations 171
Comparison Operations 171
Iterables 172
Example: Repeatable Generators 175
Sequences 176
Mappings 181
Callables 182
Context Managers 183
Taking It With You 185
Chapter 6: Object Management 186
Namespace Dictionary 187
Example: Borg Pattern 187
Example: Self-caching properties 190
Garbage Collection 193
Reference Counting 194
Cyclical References 195
Weak References 197
Pickling 199
Copying 203
Shallow Copies 204
Deep Copies 205
Taking It With You 207
Chapter 7 Strings 208
Bytes 208
Simple Conversion: chr() and ord() 209
Complex Conversion: The Struct Module 210
Text 212
Unicode 213
Encodings 213
Simple Substitution 215
Formatting 218
Looking Up Values Within Objects 219
Distinguishing Types of Strings 219
Standard Format Specification 220
Example: Plain Text Table of Contents 221
Custom Format Specification 222
Taking It With You 223
Chapter 8 Documentation 224
Proper Naming 224
Comments 225
Docstrings 225
Describe What the Function Does 226
Explain the Arguments 226
Don’t Forget the Return Value 226
Include Any Expected Exceptions 227
Documentation Outside the Code 227
Installation and Configuration 227
Tutorials 227
Reference Documents 227
Documentation Utilities 228
Formatting 229
Links 230
Sphinx 231
Taking It With You 232
Chapter 9 Testing 233
Test-Driven Development (TDD) 233
Doctests 234
Formatting Code 234
Representing Output 234
Integrating With Documentation 235
Running Tests 236
The unittest module 237
Setting Up 237
Writing Tests 238
Other Comparisons 242
Testing Strings and Other Sequence Content 242
Testing Exceptions 243
Testing Identity 245
Tearing Down 245
Providing a Custom Test Class 246
Changing Test Behavior 246
Taking It With You 247
Chapter 10 Distribution 248
Licensing 248
GNU General Public License (GPL) 248
Affero General Public License (AGPL) 249
GNU Lesser General Public License (LGPL) 250
Berkeley Software Distribution (BSD) License 250
Other Licenses 251
Packaging 251
setup.py 252
MANIFEST.in 254
The sdist command 255
Distribution 256
Taking It With You 257
Chapter 11 Sheets: A CSV Framework 258
Building a Declarative Framework 259
Introducing Declarative Programming 259
To Build or Not to Build? 260
Building the Framework 261
Managing Options 262
Defining Fields 264
Attaching a Field to a Class 265
Adding a Metaclass 267
Bringing It Together 270
Ordering Fields 271
DeclarativeMeta.__prepare__() 271
Column.__init__() 273
Column.__new__() 276
CounterMeta.__call__() 277
Choosing an Option 278
Building a Field Library 278
StringField 279
IntegerColumn 280
FloatColumn 280
DecimalColumn 280
DateColumn 281
Getting Back to CSV 285
Checking Arguments 286
Populating Values 288
The Reader 290
The Writer 294
Taking It With You 296
PEP 8 Style Guide for Python 297
Introduction 297
A Foolish Consistency is the Hobgoblin of Little Minds 297
Code Layout 298
Indentation 298
Tabs or Spaces? 298
Maximum Line Length 298
Blank Lines 298
Encodings (PEP 263) 299
Imports 299
Whitespace in Expressions and Statements 300
Pet Peeves 300
Other Recommendations 301
Comments 302
Block Comments 303
Inline Comments 303
Documentation Strings 303
Version Bookkeeping 304
Naming Conventions 304
Descriptive: Naming Styles 304
Prescriptive: Naming Conventions 305
Names to Avoid 305
Package and Module Names 305
Class Names 306
Exception Names 306
Global Variable Names 306
Function Names 306
Function and Method Arguments 306
Method Names and Instance Variables 306
Constants 307
Designing for Inheritance 307
Programming Recommendations 308
Copyright 311
PEP 10 Voting Guidelines 312
Abstract 312
Rationale 312
Voting Scores 312
Copyright 313
PEP 20 The Zen of Python 314
Abstract 314
The Zen of Python 314
Easter Egg 314
Copyright 315
PEP 257: Docstring Conventions 316
Abstract 316
Rationale 316
Specification 316
What is a Docstring? 316
One-Line Docstrings 317
Multi-Line Docstrings 318
Handling Docstring Indentation 319
Copyright 320
Acknowledgments 320
PEP 387 Backwards Compatibility Policy 321
Abstract 321
Rationale 321
Backwards Compatibility Rules 321
Making Incompatible Changes 322
Copyright 323
PEP 3000 Python 3000 324
Abstract 324
Naming 324
PEP Numbering 324
Timeline 324
Compatibility and Transition 325
Implementation Language 326
Meta-Contributions 326
Copyright 326
PEP 3003 Python Language Moratorium 327
Abstract 327
Rationale 327
Details 328
Cannot Change 328
Case-by-Case Exemptions 328
Allowed to Change 328
Retroactive 329
Extensions 329
Copyright 329
Index 330

Erscheint lt. Verlag 28.12.2010
Zusatzinfo 368 p.
Verlagsort Berkeley
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Python
Mathematik / Informatik Informatik Web / Internet
Schlagworte Communities • Framework • Management • programming • techniques
ISBN-10 1-4302-2758-3 / 1430227583
ISBN-13 978-1-4302-2758-8 / 9781430227588
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 1,3 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
Auswertung von Daten mit pandas, NumPy und Jupyter

von Wes McKinney

eBook Download (2023)
O'Reilly Verlag
44,90
Für Ein- und Umsteiger

von Bernd Klein

eBook Download (2021)
Carl Hanser Verlag GmbH & Co. KG
24,99