fluent python(非扫描版)

所需积分/C币:9 2018-06-30 22:45:03 11.87MB PDF
47
收藏 收藏
举报

This book covers: ■ The Python data model: understand how special methods are the key to the consistent behavior of objects ■ Data structures: take full advantage of built-in types, and understand the text versus bytes duality in the Unicode age ■ Functions as objects: view Python functions as first-class objects, and understand how this affects popular design patterns ■ Object-oriented idioms: build classes by learning about references, mutability, interfaces, operator overloading, and multiple inheritance ■ Control flow: leverage context managers, generators, coroutines, and concurrency with the concurrent.futures and asyncio packages ■ Metaprogramming: understand how properties, attribute descriptors, class decorators, and metaclasses work
Fluent Python Luciano ramalho Beijing. Boston· Farnham· Sebastopol.loko○ REILLY Fluent Python by luciano ramalho Copyright C 2015 Luciano Gama de Sousa Ramalho. All rights reserved Printed in the united states of america Published by o reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 OReilly books may be purchased for educational, business, or sales promotional use. Online editions are alsoavailableformosttitles(http://safaribooksonline.com).Formoreinformationcontactourcorporate institutionalsalesdepartment800-998-9938orcorporate@oreilly.com Editors: Meghan Blanchette and Rachel roumeliotis Indexer Judy mcconville Production Editor: Melanie Yarbrough Cover Designer: Ellie Volckhausen Copyeditor: Kim Cofer Interior Designer: David Futato Proofreader: Jasmine Kwityn lustrator: Rebecca demarest August 2015 First edition Revision history for the First Edition: 2015-07-24: First release 2015-08-21: Second release Seehttp://oreilly.com/catalog/errata.csp?isbn=9781491946008forreleasedetails The O Reilly logo is a registered trademark of O Reilly Media, Inc. Fluent Python, the cover image, and related trade dress are trademarks of O Reilly Media, Inc While the publisher and author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk if any code samples or other technology this work contains or describes is subject to open source licenses or the intel lectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights ISBN:978-1-491-94600-8 [LSI Para marta. com todo o meu amor Table of contents Preface Part I. Prologue The python Data Model 鲁。鲁春 A Pythonic Card Deck How Special Methods Are Used Emulating Numeric Types String representation Arithmetic Operators 12 Boolean value of a Custom Type 12 Overview of Special Method Why len Is not a method 14 Chapter Summary 14 F urther reading 15 Part Data structures 2. An Array of sequences ,,19 Overview of Built-In Sequences 20 List Comprehensions and Generator Expressions 21 List Comprehensions and readability 21 Listcomps Versus map and filter Cartesian Products 23 Generator Expressions 25 Tuples Are Not Just Immutable Lists 26 Tuples as record 26 Tuple Unpacking 27 Nested Tuple Unpacking 29 Named Tuple Tuples as Immutable Lists 32 g Why Slices and Range Exclude the Last Item 33 Slice objects 34 Multidimensional Slicing and Ellipsis A gning 36 USing and* with Sequences Building Lists of lists 37 Augmented Assignment with Sequences 38 a+= Assignment puzzler 40 list sort and the sorted Built-In function 42 Managing Ordered Sequences with bisect Searching with bisect Inserting with bisect insort When a List is not the answer 48 A 48 Memory views 51 NumPy and SciPy 52 Deques and other queues 55 Chapter Summary 5 Further reading 59 3. Dictionaries and sets Generic Mapping Types 64 dict Comprehensions 66 Overview of Common Mapping Methods 66 Handling Missing Keys with setdefault 68 Mappings with Flexible Key Lookup 70 defaultdict: Another Take on Missing Key The missing_ Method 72 Variations of dict Subclassing UserDict Immutable Mappings Set theory set literals 80 Set comprehensions 81 Set operations 82 dict and set Under the hood 85 A Performance Experiment 85 Hash tables in dictionaries 87 Table of contents Practical Consequences of How dict Works 90 How Sets Work-Practical Consequences 93 Chapter summary 93 Further readin g 94 4. Text versus Bytes 97 Character issues 8 Byte essentials 99 Structs and memory views 102 Basic encoders/decoders 103 Understanding Encode/ Decode Problems 105 Coping with UnicodeEncodeerror 105 Coping with Unicode Decode Error 106 Syntax Error When Loading Modules with Unexpected Encoding How to Discover the encoding of a Byte Sequence 109 BOM: A Useful gremlin 110 Handling Text Files 111 Encoding Defaults: A Madhouse 114 Normalizing Unicode for Saner Comparisons 117 Case folding g 119 Utility Functions for Normalized Text Matching 120 Extreme"Normalization: Taking Out Diacritics 121 Sorting unicode Text 124 Sorting with the Unicode Collation Algorithm 126 The Unicode database 127 Dual-Mode str and bytes APis 129 str Versus bytes in Regular Expressions 129 str versus bytes on os functions 130 Chapter Summary 132 Further reading 133 Part ll. Functions as objects 5. First-Class Functions 139 Treating a Function Like an Object 140 Higher-Order Functions 141 Modern Replacements for map, filter, and reduce 142 Anonymous functions 143 The Seven Flavors of Callable Objects 144 User-Defined Callable Types 145 Function Introspection 146 Table of contentsⅶi From Positional to Keyword-Only Parameters 148 Retrieving Information About Parameters 150 Function annotations 154 Packages for Functional Programming 156 The operator Module 156 Freezing Arguments with functools partial 159 Chapter summary 161 Further Reading 162 6. Design Patterns with First-Class functions 鲁。鲁。。。鲁鲁。鲁·鲁·鲁鲁。。 167 Case Study: Refactoring Strategy 168 Classic strategy 168 Function-Oriented Strategy 172 Choosing the Best Strategy Simple Approach 175 Finding Strategies in a module 176 Command 177 Chapter Summary 179 Further Reading 180 7. Function Decorators and closures ,.,.................... 183 Decorators 101 184 When Python Executes Decorators 185 ecorator-Enhanced Strategy Pattern 187 Variable Scope rules 189 Closures 192 The nonlocal declarati 195 Implementing a Simple Decorator 196 How It Works 198 tors in the Standard libra 199 Memoization with functools lru cache 200 Generic Functions with Single Dispatch 202 Stacked Decorat 205 Parameterized decorators 206 A Parameterized Registration Decorator 206 The Parameterized Clock decorator 209 Chapter Summary 211 Further Reading 212 I Table of Contents

...展开详情
试读 127P fluent python(非扫描版)
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
关注 私信
上传资源赚钱or赚积分
最新推荐
fluent python(非扫描版) 9积分/C币 立即下载
1/127
fluent python(非扫描版)第1页
fluent python(非扫描版)第2页
fluent python(非扫描版)第3页
fluent python(非扫描版)第4页
fluent python(非扫描版)第5页
fluent python(非扫描版)第6页
fluent python(非扫描版)第7页
fluent python(非扫描版)第8页
fluent python(非扫描版)第9页
fluent python(非扫描版)第10页
fluent python(非扫描版)第11页
fluent python(非扫描版)第12页
fluent python(非扫描版)第13页
fluent python(非扫描版)第14页
fluent python(非扫描版)第15页
fluent python(非扫描版)第16页
fluent python(非扫描版)第17页
fluent python(非扫描版)第18页
fluent python(非扫描版)第19页
fluent python(非扫描版)第20页

试读结束, 可继续阅读

9积分/C币 立即下载