Effective Python.pdf

所需积分/C币:50 2016-07-28 18:15:22 9.06MB PDF
6
收藏 收藏
举报

Brett Slatkin是Google的一名高级软件工程师,九年前他开始尝试使用Python来管理Google庞大的服务器群,他的建议:成为一个好的Python程序员之前毋须完全读完本书。 •课程1: 使用表达式和语句:在课程1中,你会学习到如何以Python行者的风格撰写程序,所使用的方法会影响到你将来编写的每一段程序。 •课程2: 使用解析器和生成器:在课程2中,你会学习如何使用解析器和生成器来处理和创建序列。 •课程3: 使用函数:课程3涵盖了Python函数的撰写和调用的多种独特的功能。 •课程4: 使用类:课程4聚焦于如何正确的使用Python的面向对象编程,同时避免一些常见的陷阱
Effective Python 59 SPECIFIC WAYS TO WRIE BETTER PYTHON Brett slatkin Addison-Wesley Upper saddle river,NJ· Boston· indianapolis· San francisce New york· Toronto· Montreal· London· Munich· Paris·Mad Capetown· Sydney· Tokyo· Singapore· Mexico ci!y Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the infomation or programs contained herein For information about buying this title in bulk quantities, or for special sales opportunities( which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at copsales @pearsoned com or(800)382-3419 Forgovemmentsalesinquiriespleasecontactgovernmentsales(@pearsoned.com ForquestionsaboutsalesoutsidetheUnitedstatespleasecontactinternational@pearsoned.com Visit us on the web informit com/aw Library of Congress Cataloging-in-Publication Data Slatkin. Brett. author Effective Python: 59 specific ways to write better Python/Brett Slatkin pages cm Includes index sBN978-0-13-403428-7(pbk.ak. paper}-SBN0-13-403428-7(pbk.ak. paper) 1. Python(Computer program language)2. Computer programming. I. Title QA76.73P98s572015 005.133-dc23 2014048305 Copyright C 2015 Pearson Education, Inc All rights reserved Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical Inc, Permissions Department, One Lake Street. Upper Saddle River, New Jersey 07458, or you may fax your request to(201)236-3290 ucation photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson edr sBN-13:978-0-13-403428-7 sBN-10:0-13-403428-7 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville. Indiana First printing March 2015 Editor-in-Chief Mark l. taub Senior Acquisitions Editor Trina macDonald Managing Editor John fuller Full-Service Production Manager Julie b. nahil Copy Editor Stephanie Geels Indexer Jack lewis Proofreader Melissa panagos Technical Reviewers Brett cannon Tavis Rudd Mike Taylor Editorial assistant Olivia basegio Cover Designer Chuti Prasertsith Compositor aurellech Praise for Effective Python "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 Ive 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 to make it faster(e.g, using bui It-in data structures), easier to read(e.g, enforcing keyword- only arguments ) and much more Pythonic(e.g, using zip to iterate over lists in parallel) -Pamela Fox, educationeer, Khan Academy if I had this book when I first switched from Java to Python, it would have saved me many months of repeated code rewrites which happened each time I realized l was doing particular things'non-Pythonically. this book collects the vast majority of basic Python'must-knows' into one place, eliminating the need to stumble upon them one-by-one over the course of months or years. The scope of the book is impressive, starting with the importance of PEP8 as well as that of major Python idioms, then reaching through function, method and class design, effective standard library use, quality API design, testing, and performance measurement-this book really has it all. a fantastic introduction to what it really means to be a Python programmer for both the novice and the experienced developer -Mike Bayer, creator of SQLAlchemy Effective Python will take your Python skills to the next level with clear guidelines for improving Python code style and function -Leah Culver, developer advocate, Dropbox This book is an exceptionally great re source for seasoned developers in other languages who are looking to quickly pick up Python and move beyond the basic language constructs into more Pythonic code. The organization of the book is clear, concise, and easy to digest, and each item and chapter can stand on its own as a meditation on a particular topic. The book covers the breadth of language constructs in pure Python without confusing the reader with the complexities of the broader Python ecosystem For more seasoned developers the book provides in-depth examples of language constructs they may not have previously encountered, and provides examples of less commonly used language features. It common failure modes. Furthermore, the book does an excellent job of pointing out subtleties between Python 2.X and Python 3. x and colly and is clear that the author is exceptionally facile with Python, and he uses his professional experience to alert the reader to common subtle bugs serve as a refresher course as one transitions between variants of python -Katherine Scott, sofware lead, Tempo Automation This is a great book for both novice and experienced programmers. The code examples and explanations are well thought out and explained concisely and thoroughly -C. Titus Brown associate professor, UC Davis This is an immensely useful resource for advanced python usage and building cleaner, more maintainable software. Anyone looking to take their Python skills to the next level would benefit from putting the books advice into practice Wes McKinney, creator of pandas; author of Python for Data Analysis; and software engineer at Cloudera The Effective Software Development Series Scott Meyers, Consulting Editor e Effeetive E/lective Effective C# C20 PROGRAMMING AAddison-Wesley visit intermit, cam/esds for a complete list of avallable publications. The a Eflective saftware Development series prowdes expert advice o all aspects of rodern soft ait Hevelopment I tles in the series are well written, technica y ssnd, anc Ef lasting value. Lach describes the critical things experts always da-otaways 3ddd-to pod e outstanding sottware. Scott Meyers, aurhor cf the best-selling books Effectve C ++ (now in its thid edit on woe Efective G++ an c Effective STL (all avallable in both print and election ve sinst conceived of te senas and acts as its consulting editor. Authors in the serles wo k wI Meyes to cname essential reading In a format that is familiar and accessible for softwale developers of RvEr/ stripe MLaka sure ta connect with ul Intormit.comaDdLison-wesleysafari ALWAn5上 SUMING PEARSON To our family, /oved and lost Contents Preface Acknowledgments About the author Chapter 1: Pythonic Thinking item 1: Know Which Version of Python You're using item 2: Follow the pEP 8 style Guide item 3: Know the Differences Between bytes, str, and unicode item 4: Write Helper Functions Instead of complex Expressions Item 5: Know How to Slice Sequences Item 6: Avoid Using star- en:, and st ride in a Single slice Item 7: Use List Comprehensions Instead of map and filter Item 8: Avoid More Than Two Expressions in List Comprehensions Item 9: Consider Generator Expressions for Large Comprehensions Item 10: Prefer enumerate Over range Item 11: Use zip to Process iterators in Parallel item 12: Avoid else blocks After for and while Loops Item 13: Take Advantage of each Block in trvlexceptlelse/finall Chapter 2: Functions item 14: Prefer Exceptions to Returning None Item 15: Know How Closures Interact with variable Scope Item 16: Consider Generators Instead of returning lists Item 17: Be Defensive When Iterating Over Arguments Item 18: Reduce Visual Noise with Variable Positional Arguments item 19: Provide optional behavior with Keword Arguments Item 20: Use \one and Docstrings to Specity Dynamic Default Arguments Item 21: Enforce Clarity with Keword-Only Arguments Chapter 3: Classes and Inheritance ltem 22: Prefer Helper Classes Over Bookkeeping with Dictionaries and Tuples Item 23: Accept Functions for Simple Interfaces Instead of classes Item 24: Use aclassme-hod Polymorphism to Construct Obiects Generically Item 25: initialize Parent Classes with super item 26: Use Multiple Inheritance Only for Mix-in Utility classes Item 27: Prefer Public Attributes Over private ones ltem 28: Inherit from collections. abc for Custom Container Types Chapter 4: Metaclasses and Attributes Item 29: Use plain attributes Instead of get and set methods Item 30: Consider (property Instead of Refactoring Attributes Item 31: Use Descriptors for Reusable apra perty Methods Item 32: Use getattr getattribute, and for Lazy Attributes Item 33 Validate Subclasses with metaclasses Item 34: Register Class Existence with Metaclasses Item 35: annotate class attributes with metaclasses Chapter 5: Concurrency and Parallelism Item 36: Use subprocess to Manage child Processes item 37: Use Threads for Blocking vO, Avoid for Parallelism Item 38 Use loc 's to prevent data races in threads Item 39: Use Queue to coordinate work between threads Item 40: Consider Coroutines to Run Many Functions Concurrently Item 41: Consider concurrent futures for True Parallelism Chapter 6: Built-in Modules Item 42: Define Function Decorators with sunctoolswrap Item 43: Consider contex=lib and with Statements for Reusable try/final_y behavior Item 44: Make pickle reliable with copvrec Item 45: Use cater ime Instead of t ime for local c locks item 46: Use Built-in Algorithms and Data Structures Item 47, Use cec imal When precision ks paramount Item 48: Know Where to Find Community-Built Modules Chapter 7: Collaboration Item 49: Write Docstrings for Every Function, Class and module Item 50: Use Packages to Organize Modules and Provide stable APls Item 51: Define a Root Exception to Insulate Callers from APls item 52: Know How to Break Circular Dependencies Item 53: Use virtual Environments for Isolated and Reproducible Dependencies Chapter 8: Production Item 54: Consider Module-Scoped Code to Configure Deployment Environments Item 55: Use repr strings for Debugging outout Item 56: Test Everything with unittest Item 57: Consider Interactive Debugging with pdb item 58: Profile Before Optimizing Item 59: Use tracemalloc to Understand Memory Usage and leaks Index

...展开详情
试读 127P Effective Python.pdf
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
我家果果 非常容易理解,不错的书 感谢资源提供者
2020-05-09
回复
离离原上草_# 谢谢分享,标题内容相符
2019-01-09
回复
会飞的蚂蚁_ 非常受用,正在提升python
2018-09-14
回复
凌龙无敌 不错的书,可以看看
2018-05-02
回复
FreezeTime1 非常容易理解,感谢资源提供者
2018-04-22
回复
hellobeach 很好, 更容易理解 英文术语了
2018-02-06
回复
chensimmons 英文版,感谢
2017-12-29
回复
zhifeng610 举例了很多小的示例,利于阅读,还可以
2017-11-14
回复
fujialin2011 不错,下载学学
2017-11-09
回复
z15062924270l 下载失败, 重新下载.
2017-10-26
回复
  • GitHub

    绑定GitHub第三方账户获取
关注 私信 TA的资源
上传资源赚积分or赚钱
    最新推荐
    Effective Python.pdf 50积分/C币 立即下载
    1/127
    Effective Python.pdf第1页
    Effective Python.pdf第2页
    Effective Python.pdf第3页
    Effective Python.pdf第4页
    Effective Python.pdf第5页
    Effective Python.pdf第6页
    Effective Python.pdf第7页
    Effective Python.pdf第8页
    Effective Python.pdf第9页
    Effective Python.pdf第10页
    Effective Python.pdf第11页
    Effective Python.pdf第12页
    Effective Python.pdf第13页
    Effective Python.pdf第14页
    Effective Python.pdf第15页
    Effective Python.pdf第16页
    Effective Python.pdf第17页
    Effective Python.pdf第18页
    Effective Python.pdf第19页
    Effective Python.pdf第20页

    试读结束, 可继续阅读

    50积分/C币 立即下载 >