SØG - mellem flere end 8 millioner bøger:

Søg på: Titel, forfatter, forlag - gerne i kombination.
Eller blot på isbn, hvis du kender dette.

Viser: Effective Python - 59 Specific Ways to Write Better Python

Effective Python - 59 Specific Ways to Write Better Python

Effective Python

59 Specific Ways to Write Better Python
Brett Slatkin
(2015)
Sprog: Engelsk
Pearson Education, Limited
339,00 kr. 305,10 kr.
ikke på lager, Bestil nu og få den leveret
om ca. 10 hverdage

Detaljer om varen

  • Paperback: 256 sider
  • Udgiver: Pearson Education, Limited (Marts 2015)
  • ISBN: 9780134034287
"Each item in Slatkin's Effective Python teaches a self-contained lesson with its own source code. This makes the book random-access: Items are easy to browse and study in whatever order the reader needs. I will be recommending Effective Python to students as an admirably compact source of mainstream advice on a very broad range of topics for the intermediate Python programmer."

--Brandon Rhodes, software engineer at Dropbox and chair of PyCon 2016-2017

It's easy to start coding with Python, which is why the language is so popular. However, Python's unique strengths, charms, and expressiveness can be hard to grasp, and there are hidden pitfalls that can easily trip you up.

Effective Python will help you master a truly "Pythonic" approach to programming, harnessing Python's full power to write exceptionally robust and well-performing code. Using the concise, scenario-driven style pioneered in Scott Meyers' best-selling Effective C++, Brett Slatkin brings together 59 Python best practices, tips, and shortcuts, and explains them with realistic code examples.

Drawing on years of experience building Python infrastructure at Google, Slatkin uncovers little-known quirks and idioms that powerfully impact code behavior and performance. You'll learn the best way to accomplish key tasks, so you can write code that's easier to understand, maintain, and improve.

Key features include

  • Actionable guidelines for all major areas of Python 3.x and 2.x development, with detailed explanations and examples
  • Best practices for writing functions that clarify intention, promote reuse, and avoid bugs
  • Coverage of how to accurately express behaviors with classes and objects
  • Guidance on how to avoid pitfalls with metaclasses and dynamic attributes
  • More efficient approaches to concurrency and parallelism
  • Better techniques and idioms for using Python's built-in modules
  • Tools and best practices for collaborative development
  • Solutions for debugging, testing, and optimization in order to improve quality and performance
Preface xiii Acknowledgments xvii About the Author xix
Chapter 1: Pythonic Thinking 1 Item
1: Know Which Version of Python You''re Using 1 Item
2: Follow the PEP 8 Style Guide 2 Item
3: Know the Differences Between bytes, str, and unicode 5 Item
4: Write Helper Functions Instead of Complex Expressions 8 Item
5: Know How to Slice Sequences 10 Item
6: Avoid Using start, end, and stride in a Single Slice 13 Item
7: Use List Comprehensions Instead of map and filter 15 Item
8: Avoid More Than Two Expressions in List Comprehensions 16 Item
9: Consider Generator Expressions for Large Comprehensions 18 Item
10: Prefer enumerate Over range 20 Item
11: Use zip to Process Iterators in Parallel 21 Item
12: Avoid else Blocks After for and while Loops 23 Item
13: Take Advantage of Each Block in try/except/else/finally 26
Chapter 2: Functions 29 Item
14: Prefer Exceptions to Returning None 29 Item
15: Know How Closures Interact with Variable Scope 31 Item
16: Consider Generators Instead of Returning Lists 36 Item
17: Be Defensive When Iterating Over Arguments 38 Item
18: Reduce Visual Noise with Variable Positional Arguments 43 Item
19: Provide Optional Behavior with Keyword Arguments 45 Item
20: Use None and Docstrings to Specify Dynamic Default Arguments 48 Item
21: Enforce Clarity with Keyword-Only Arguments 51
Chapter 3: Classes and Inheritance 55 Item
22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples 55 Item
23: Accept Functions for Simple Interfaces Instead of Classes 61 Item
24: Use @classmethod Polymorphism to Construct Objects Generically 64 Item
25: Initialize Parent Classes with super 69 Item
26: Use Multiple Inheritance Only for Mix-in Utility Classes 73 Item
27: Prefer Public Attributes Over Private Ones 78 Item
28: Inherit from collections.abc for Custom Container Types 83
Chapter 4: Metaclasses and Attributes 87 Item
29: Use Plain Attributes Instead of Get and Set Methods 87 Item
30: Consider @property Instead of Refactoring Attributes 91 Item
31: Use Descriptors for Reusable @property Methods 95 Item
32: Use __getattr__, __getattribute__, and __setattr__ for Lazy Attributes 100 Item
33: Validate Subclasses with Metaclasses 105 Item
34: Register Class Existence with Metaclasses 108 Item
35: Annotate Class Attributes with Metaclasses 112
Chapter 5: Concurrency and Parallelism 117 Item
36: Use subprocess to Manage Child Processes 118 Item
37: Use Threads for Blocking I/O, Avoid for Parallelism 122 Item
38: Use Lock to Prevent Data Races in Threads 126 Item
39: Use Queue to Coordinate Work Between Threads 129 Item
40: Consider Coroutines to Run Many Functions Concurrently 136 Item
41: Consider concurrent.futures for True Parallelism 145
Chapter 6: Built-in Modules 151 Item
42: Define Function Decorators with functools.wraps 151 Item
43: Consider contextlib and with Statements for Reusable try/finally Behavior 153 Item
44: Make pickle Reliable with copyreg 157 Item
45: Use datetime Instead of time for Local Clocks 162 Item
46: Use Built-in Algorithms and Data Structures 166 Item
47: Use decimal When Precision Is Paramount 171 Item
48: Know Where to Find Community-Built Modules 173
Chapter 7: Collaboration 175 Item
49: Write Docstrings for Every Function, Class, and Module 175 Item
50: Use Packages to Organize Modules and Provide Stable APIs 179 Item
51: Define a Root Exception to Insulate Callers from APIs 184 Item
52: Know How to Break Circular Dependencies 187 Item
53: Use Virtual Environments for Isolated and Reproducible Dependencies 192
Chapter 8: Production 199 Item
54: Consider Module-Scoped Code to Configure Deployment Environments 199 Item
55: Use repr Strings for Debugging Output 202 Item
56: Test Everything with unittest 204 Item
57: Consider Interactive Debugging with pdb 208 Item
58: Profile Before Optimizing 209 Item
59: Use tracemalloc to Understand Memory Usage and Leaks 214 Index 217
De oplyste priser er inkl. moms

Senest sete

Polyteknisk Boghandel

har gennem mere end 50 år været studieboghandlen på DTU og en af Danmarks førende specialister i faglitteratur.

 

Vi lagerfører et bredt udvalg af bøger, ikke bare inden for videnskab og teknik, men også f.eks. ledelse, IT og meget andet.

Læs mere her


Trykt eller digital bog?

Ud over trykte bøger tilbyder vi tre forskellige typer af digitale bøger:

 

Vital Source Bookshelf: En velfungerende ebogsplatform, hvor bogen downloades til din computer og/eller mobile enhed.

 

Du skal bruge den gratis Bookshelf software til at læse læse bøgerne - der er indbygget gode værktøjer til f.eks. søgning, overstregning, notetagning mv. I langt de fleste tilfælde vil du samtidig have en sideløbende 1825 dages online adgang. Læs mere om Vital Source bøger

 

Levering: I forbindelse med købet opretter du et login. Når du har installeret Bookshelf softwaren, logger du blot ind og din bog downloades automatisk.

 

 

Adobe ebog: Dette er Adobe DRM ebøger som downloades til din lokale computer eller mobil enhed.

 

For at læse bøgerne kræves særlig software, som understøtter denne type. Softwaren er gratis, men du bør sikre at du har rettigheder til installere software på den maskine du påtænker at anvende den på. Læs mere om Adobe DRM bøger

 

Levering: Et download link sendes pr email umiddelbart efter købet.

 


Ibog: Dette er en online bog som kan læses på udgiverens website. 

Der kræves ikke særlig software, bogen læses i en almindelig browser.

 

Levering: Vores medarbejder sender dig en adgangsnøgle pr email.

 

Vi gør opmærksom på at der ikke er retur/fortrydelsesret på digitale varer.