设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 494|回复: 0

[Python] 《Python 3 Patterns, Recipes and Idioms》

[复制链接]

93

主题

3169

金钱

3777

积分

中级用户

发表于 2018-11-7 13:27:16 | 显示全部楼层 |阅读模式

《Python 3 Patterns, Recipes and Idioms》
pdf
1 Contributors 1
1.1 Thanks To . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 ToDo List 3
3 The remainder are from context, from the book. 5
4 A Note To Readers 7
5 Introduction 9
5.1 A Team Effort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.2 Not an Introductory Book . . . . . . . . . . . . . . . . . . . . . . . . 10
5.3 The License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.4 The Printed Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.5 Translations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.6 My Motives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 Teaching Support 13
7 Book Development Rules 15
7.1 Contribute What You Can . . . . . . . . . . . . . . . . . . . . . . . . 15
7.2 Don’t Get Attached . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.3 Credit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.4 Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7.5 Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8 Developer Guide 21
8.1 Getting Started: The Easiest Approach . . . . . . . . . . . . . . . . 21
8.2 For Windows Users . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8.3 Installing Sphinx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8.4 Getting the Development Branch of the Book . . . . . . . . . . . . . 23
8.5 Building the Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8.6 Building the PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8.7 Setting up Mercurial . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
8.8 Working with BitBucket and Mercurial . . . . . . . . . . . . . . . . 25
8.9 A Simple Overview Of Editing and Merging . . . . . . . . . . . . . 27
8.10 Emacs for Editing Restructured Text . . . . . . . . . . . . . . . . . . 27
9 Part I: Foundations 31
10 Quick Python for Programmers 33
10.1 Scripting vs. Programming . . . . . . . . . . . . . . . . . . . . . . . 34
10.2 Built-In Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
10.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
10.4 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
10.5 Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
11 Unit Testing & Test-Driven Development 43
11.1 Write Tests First . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
11.2 Simple Python Testing . . . . . . . . . . . . . . . . . . . . . . . . . . 46
11.3 A Very Simple Framework . . . . . . . . . . . . . . . . . . . . . . . 47
11.4 Writing Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
11.5 White-Box & Black-Box Tests . . . . . . . . . . . . . . . . . . . . . . 51
11.6 Running tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
11.7 Automatically Executing Tests . . . . . . . . . . . . . . . . . . . . . 55
11.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
12 Python 3 Language Changes 57
13 Decorators 59
13.1 Decorators vs. the Decorator Pattern . . . . . . . . . . . . . . . . . . 59
13.2 History of Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
13.3 The Goal of Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
13.4 What Can You Do With Decorators? . . . . . . . . . . . . . . . . . . 61
13.6 Slightly More Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
13.7 Using Functions as Decorators . . . . . . . . . . . . . . . . . . . . . 64
13.8 Review: Decorators without Arguments . . . . . . . . . . . . . . . 66
13.9 Decorators with Arguments . . . . . . . . . . . . . . . . . . . . . . . 67
13.10 Decorator Functions with Decorator Arguments . . . . . . . . . . . 69
13.11 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
14 Generators, Iterators, and Itertools 73
15 Comprehensions 75
15.1 A More Complex Example . . . . . . . . . . . . . . . . . . . . . . . 75
16 Coroutines & Concurrency 81
16.1 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
17 Jython 83
17.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
17.2 Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
17.3 Interpreter Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . 87
17.4 Using Java libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
17.5 Controlling Java from Jython . . . . . . . . . . . . . . . . . . . . . . 93
17.6 Controlling the Interpreter . . . . . . . . . . . . . . . . . . . . . . . 97
17.7 Creating Java classes with Jython . . . . . . . . . . . . . . . . . . . 107
17.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
17.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
18 Part II: Idioms 117
19 Discovering the Details About Your Platform 119
20 A Canonical Form for Command-Line Programs 121
21 Messenger/Data Transfer Object 123
22 Part III: Patterns 125
23 The Pattern Concept 127
23.1 What is a Pattern? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
23.2 Classifying Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
23.3 Pattern Taxonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
23.4 Design Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
23.5 Design Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
24 The Singleton 135
24.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
25 Building Application Frameworks 143
25.1 Template Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
25.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
26 Fronting for an Implementation 145
26.1 Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
26.2 State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
27 StateMachine 151
27.1 Table-Driven State Machine . . . . . . . . . . . . . . . . . . . . . . . 158
27.2 Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
27.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
28 Decorator: Dynamic Type Selection 171
28.1 Basic Decorator Structure . . . . . . . . . . . . . . . . . . . . . . . . 172
28.2 A Coffee Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
28.3 Class for Each Combination . . . . . . . . . . . . . . . . . . . . . . . 173
28.4 The Decorator Approach . . . . . . . . . . . . . . . . . . . . . . . . 175
28.5 Compromise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
28.6 Other Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 181
28.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
29 Iterators: Decoupling Algorithms from Containers 183
29.1 Type-Safe Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
30 Factory: Encapsulating Object Creation 187
30.1 Simple Factory Method . . . . . . . . . . . . . . . . . . . . . . . . . 188
30.2 Polymorphic Factories . . . . . . . . . . . . . . . . . . . . . . . . . . 191
30.3 Abstract Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
30.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
31 Function Objects 199
31.1 Command: Choosing the Operation at Runtime . . . . . . . . . . . 199
31.2 Strategy: Choosing the Algorithm at Runtime . . . . . . . . . . . . 201
31.3 Chain of Responsibility . . . . . . . . . . . . . . . . . . . . . . . . . 202
31.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
32 Changing the Interface 207
32.1 Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
32.2 Façade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
32.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
33 Table-Driven Code: Configuration Flexibility 211
33.1 Table-Driven Code Using Anonymous Inner Classes . . . . . . . . 211
34 Observer 213
34.1 Observing Flowers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
35 Multiple Dispatching 231
36 Visitor 237
36.1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
37 Pattern Refactoring 241
37.1 Simulating the Trash Recycler . . . . . . . . . . . . . . . . . . . . . 241
37.2 Improving the Design . . . . . . . . . . . . . . . . . . . . . . . . . . 245
37.3 A Pattern for Prototyping Creation . . . . . . . . . . . . . . . . . . . 249
37.4 Abstracting Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
37.5 Multiple Dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . 262
37.6 The Visitor Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
37.7 RTTI Considered Harmful? . . . . . . . . . . . . . . . . . . . . . . . 279
37.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
37.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
38 Projects 285
38.1 Rats & Mazes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
39 Indices and tables 291
Index 293








Python 3 Patterns, Recipes and Idioms .pdf

1019.78 KB, 下载次数: 0

售价: 2 金钱  [记录]  [购买]

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表