skip to content
Covid-19 virus
COVID-19 Resources

Reliable information about the coronavirus (COVID-19) is available from the World Health Organization (current situation, international travel). Numerous and frequently-updated resource results are available from this WorldCat.org search. OCLC’s WebJunction has pulled together information and resources to assist library staff as they consider how to handle coronavirus issues in their communities.

Image provided by: CDC/ Alissa Eckert, MS; Dan Higgins, MAM
Effective Python : 59 specific ways to write better Python Preview this item
ClosePreview this item
Checking...

Effective Python : 59 specific ways to write better Python

Author: Brett Slatkin
Publisher: Upper Saddle River, N.J. : Addison-Wesley, 2015
Series: Effective software development series
Edition/Format:   Print book : EnglishView all editions and formats
Summary:
"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  Read more...
Rating:

(not yet rated) 0 with reviews - Be the first.

Subjects
More like this

Find a copy in the library

&AllPage.SpinnerRetrieving; Finding libraries that hold this item...

Details

Document Type: Book
All Authors / Contributors: Brett Slatkin
ISBN: 9780134034287 0134034287
OCLC Number: 1005700616
Notes: Includes index
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 ...
Description: xix, 227 pages : illustrations
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
Series Title: Effective software development series
Responsibility: Brett Slatkin

Abstract:

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

Reviews

Editorial reviews

Publisher Synopsis

"I've been programming in Python for years and thought I knew it pretty well. Thanks to this treasure trove of tips and techniques, I realize there's so much more I could be doing with my Python code Read more...

 
User-contributed reviews
Retrieving GoodReads reviews...
Retrieving DOGObooks reviews...

Tags

Be the first.
Confirm this request

You may have already requested this item. Please select Ok if you would like to proceed with this request anyway.

Linked Data


\n\n

Primary Entity<\/h3>\n
<http:\/\/www.worldcat.org\/oclc\/1005700616<\/a>> # Effective Python : 59 specific ways to write better Python<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Book<\/a>, schema:CreativeWork<\/a> ;\u00A0\u00A0\u00A0\nlibrary:oclcnum<\/a> \"1005700616<\/span>\" ;\u00A0\u00A0\u00A0\nlibrary:placeOfPublication<\/a> <http:\/\/id.loc.gov\/vocabulary\/countries\/nju<\/a>> ;\u00A0\u00A0\u00A0\nlibrary:placeOfPublication<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Place\/upper_saddle_river_n_j<\/a>> ; # Upper Saddle River, N.J.<\/span>\n\u00A0\u00A0\u00A0\nschema:about<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Topic\/computer_programming<\/a>> ; # Computer programming<\/span>\n\u00A0\u00A0\u00A0\nschema:about<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Thing\/computers_and_it<\/a>> ; # Computers and IT<\/span>\n\u00A0\u00A0\u00A0\nschema:about<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Topic\/python_computer_program_language<\/a>> ; # Python (Computer program language)<\/span>\n\u00A0\u00A0\u00A0\nschema:bookFormat<\/a> bgn:PrintBook<\/a> ;\u00A0\u00A0\u00A0\nschema:contributor<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Person\/slatkin_brett<\/a>> ; # Brett Slatkin<\/span>\n\u00A0\u00A0\u00A0\nschema:datePublished<\/a> \"2015<\/span>\" ;\u00A0\u00A0\u00A0\nschema:datePublished<\/a> \"2017<\/span>\" ;\u00A0\u00A0\u00A0\nschema:description<\/a> \"\"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.-<\/span>\" ;\u00A0\u00A0\u00A0\nschema:exampleOfWork<\/a> <http:\/\/worldcat.org\/entity\/work\/id\/2506849491<\/a>> ;\u00A0\u00A0\u00A0\nschema:inLanguage<\/a> \"en<\/span>\" ;\u00A0\u00A0\u00A0\nschema:isPartOf<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Series\/effective_software_development_series<\/a>> ; # Effective software development series<\/span>\n\u00A0\u00A0\u00A0\nschema:name<\/a> \"Effective Python : 59 specific ways to write better Python<\/span>\" ;\u00A0\u00A0\u00A0\nschema:productID<\/a> \"1005700616<\/span>\" ;\u00A0\u00A0\u00A0\nschema:publication<\/a> <http:\/\/www.worldcat.org\/title\/-\/oclc\/1005700616#PublicationEvent\/upper_saddle_river_n_j_addison_wesley_2015<\/a>> ;\u00A0\u00A0\u00A0\nschema:publisher<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Agent\/addison_wesley<\/a>> ; # Addison-Wesley<\/span>\n\u00A0\u00A0\u00A0\nschema:workExample<\/a> <http:\/\/worldcat.org\/isbn\/9780134034287<\/a>> ;\u00A0\u00A0\u00A0\nwdrs:describedby<\/a> <http:\/\/www.worldcat.org\/title\/-\/oclc\/1005700616<\/a>> ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n\n

Related Entities<\/h3>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Agent\/addison_wesley<\/a>> # Addison-Wesley<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nbgn:Agent<\/a> ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Addison-Wesley<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Person\/slatkin_brett<\/a>> # Brett Slatkin<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Person<\/a> ;\u00A0\u00A0\u00A0\nschema:familyName<\/a> \"Slatkin<\/span>\" ;\u00A0\u00A0\u00A0\nschema:givenName<\/a> \"Brett<\/span>\" ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Brett Slatkin<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Place\/upper_saddle_river_n_j<\/a>> # Upper Saddle River, N.J.<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Place<\/a> ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Upper Saddle River, N.J.<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Series\/effective_software_development_series<\/a>> # Effective software development series<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nbgn:PublicationSeries<\/a> ;\u00A0\u00A0\u00A0\nschema:hasPart<\/a> <http:\/\/www.worldcat.org\/oclc\/1005700616<\/a>> ; # Effective Python : 59 specific ways to write better Python<\/span>\n\u00A0\u00A0\u00A0\nschema:name<\/a> \"Effective software development series<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Thing\/computers_and_it<\/a>> # Computers and IT<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Thing<\/a> ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Computers and IT<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Topic\/computer_programming<\/a>> # Computer programming<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Intangible<\/a> ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Computer programming<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Topic\/python_computer_program_language<\/a>> # Python (Computer program language)<\/span>\n\u00A0\u00A0\u00A0\u00A0a \nschema:Intangible<\/a> ;\u00A0\u00A0\u00A0\nschema:name<\/a> \"Python (Computer program language)<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/id.loc.gov\/vocabulary\/countries\/nju<\/a>>\u00A0\u00A0\u00A0\u00A0a \nschema:Place<\/a> ;\u00A0\u00A0\u00A0\ndcterms:identifier<\/a> \"nju<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/worldcat.org\/isbn\/9780134034287<\/a>>\u00A0\u00A0\u00A0\u00A0a \nschema:ProductModel<\/a> ;\u00A0\u00A0\u00A0\nschema:isbn<\/a> \"0134034287<\/span>\" ;\u00A0\u00A0\u00A0\nschema:isbn<\/a> \"9780134034287<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/www.worldcat.org\/title\/-\/oclc\/1005700616<\/a>>\u00A0\u00A0\u00A0\u00A0a \ngenont:InformationResource<\/a>, genont:ContentTypeGenericResource<\/a> ;\u00A0\u00A0\u00A0\nschema:about<\/a> <http:\/\/www.worldcat.org\/oclc\/1005700616<\/a>> ; # Effective Python : 59 specific ways to write better Python<\/span>\n\u00A0\u00A0\u00A0\nschema:dateModified<\/a> \"2019-12-23<\/span>\" ;\u00A0\u00A0\u00A0\nvoid:inDataset<\/a> <http:\/\/purl.oclc.org\/dataset\/WorldCat<\/a>> ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n
<http:\/\/www.worldcat.org\/title\/-\/oclc\/1005700616#PublicationEvent\/upper_saddle_river_n_j_addison_wesley_2015<\/a>>\u00A0\u00A0\u00A0\u00A0a \nschema:PublicationEvent<\/a> ;\u00A0\u00A0\u00A0\nschema:location<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Place\/upper_saddle_river_n_j<\/a>> ; # Upper Saddle River, N.J.<\/span>\n\u00A0\u00A0\u00A0\nschema:organizer<\/a> <http:\/\/experiment.worldcat.org\/entity\/work\/data\/2506849491#Agent\/addison_wesley<\/a>> ; # Addison-Wesley<\/span>\n\u00A0\u00A0\u00A0\nschema:startDate<\/a> \"2015<\/span>\" ;\u00A0\u00A0\u00A0\u00A0.\n\n\n<\/div>\n\n

Content-negotiable representations<\/p>\n