Effective Python
Home > Computing and Information Technology > Computer programming / software engineering > Programming and scripting languages: general > 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


     0     
5
4
3
2
1



Out of Stock


Notify me when this book is in stock
X
About the Book

“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

Table of Contents:
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

About the Author :
Brett Slatkin, senior staff software engineer at Google, is engineering lead and co-founder of Google Consumer Surveys. He previously worked on Google App Engine’s Python infrastructure, leveraged Python to manage Google’s enormous server fleet, and used Python to implement Google's system for PubSubHubbub, a protocol he co-created. Slatkin holds a B.S. in computer engineering from Columbia University in the City of New York. He lives in San Francisco.


Best Sellers


Product Details
  • ISBN-13: 9780134034386
  • Publisher: Pearson Education (US)
  • Publisher Imprint: Addison Wesley
  • Language: English
  • Sub Title: 59 Specific Ways to Write Better Python
  • ISBN-10: 0134034384
  • Publisher Date: 12 Feb 2015
  • Binding: Digital download
  • No of Pages: 256
  • Weight: 1 gr


Similar Products

Add Photo
Add Photo

Customer Reviews

REVIEWS      0     
Click Here To Be The First to Review this Product
Effective Python: 59 Specific Ways to Write Better Python
Pearson Education (US) -
Effective Python: 59 Specific Ways to Write Better Python
Writing guidlines
We want to publish your review, so please:
  • keep your review on the product. Review's that defame author's character will be rejected.
  • Keep your review focused on the product.
  • Avoid writing about customer service. contact us instead if you have issue requiring immediate attention.
  • Refrain from mentioning competitors or the specific price you paid for the product.
  • Do not include any personally identifiable information, such as full names.

Effective Python: 59 Specific Ways to Write Better Python

Required fields are marked with *

Review Title*
Review
    Add Photo Add up to 6 photos
    Would you recommend this product to a friend?
    Tag this Book Read more
    Does your review contain spoilers?
    What type of reader best describes you?
    I agree to the terms & conditions
    You may receive emails regarding this submission. Any emails will include the ability to opt-out of future communications.

    CUSTOMER RATINGS AND REVIEWS AND QUESTIONS AND ANSWERS TERMS OF USE

    These Terms of Use govern your conduct associated with the Customer Ratings and Reviews and/or Questions and Answers service offered by Bookswagon (the "CRR Service").


    By submitting any content to Bookswagon, you guarantee that:
    • You are the sole author and owner of the intellectual property rights in the content;
    • All "moral rights" that you may have in such content have been voluntarily waived by you;
    • All content that you post is accurate;
    • You are at least 13 years old;
    • Use of the content you supply does not violate these Terms of Use and will not cause injury to any person or entity.
    You further agree that you may not submit any content:
    • That is known by you to be false, inaccurate or misleading;
    • That infringes any third party's copyright, patent, trademark, trade secret or other proprietary rights or rights of publicity or privacy;
    • That violates any law, statute, ordinance or regulation (including, but not limited to, those governing, consumer protection, unfair competition, anti-discrimination or false advertising);
    • That is, or may reasonably be considered to be, defamatory, libelous, hateful, racially or religiously biased or offensive, unlawfully threatening or unlawfully harassing to any individual, partnership or corporation;
    • For which you were compensated or granted any consideration by any unapproved third party;
    • That includes any information that references other websites, addresses, email addresses, contact information or phone numbers;
    • That contains any computer viruses, worms or other potentially damaging computer programs or files.
    You agree to indemnify and hold Bookswagon (and its officers, directors, agents, subsidiaries, joint ventures, employees and third-party service providers, including but not limited to Bazaarvoice, Inc.), harmless from all claims, demands, and damages (actual and consequential) of every kind and nature, known and unknown including reasonable attorneys' fees, arising out of a breach of your representations and warranties set forth above, or your violation of any law or the rights of a third party.


    For any content that you submit, you grant Bookswagon a perpetual, irrevocable, royalty-free, transferable right and license to use, copy, modify, delete in its entirety, adapt, publish, translate, create derivative works from and/or sell, transfer, and/or distribute such content and/or incorporate such content into any form, medium or technology throughout the world without compensation to you. Additionally,  Bookswagon may transfer or share any personal information that you submit with its third-party service providers, including but not limited to Bazaarvoice, Inc. in accordance with  Privacy Policy


    All content that you submit may be used at Bookswagon's sole discretion. Bookswagon reserves the right to change, condense, withhold publication, remove or delete any content on Bookswagon's website that Bookswagon deems, in its sole discretion, to violate the content guidelines or any other provision of these Terms of Use.  Bookswagon does not guarantee that you will have any recourse through Bookswagon to edit or delete any content you have submitted. Ratings and written comments are generally posted within two to four business days. However, Bookswagon reserves the right to remove or to refuse to post any submission to the extent authorized by law. You acknowledge that you, not Bookswagon, are responsible for the contents of your submission. None of the content that you submit shall be subject to any obligation of confidence on the part of Bookswagon, its agents, subsidiaries, affiliates, partners or third party service providers (including but not limited to Bazaarvoice, Inc.)and their respective directors, officers and employees.

    Accept

    New Arrivals


    Inspired by your browsing history


    Your review has been submitted!

    You've already reviewed this product!