...............................................................................................5
数据描述对象....................................................................................................................5
行为是动作.........................................................................................................................7
隐藏细节并且创建公共接口..............................................................................................8
组合和继承.........................................................................................................................10
继承.....................................................................................................................................12
案例学习.............................................................................................................................15
练习.....................................................................................................................................22
总结.....................................................................................................................................23
第2章Python对象........................................................................................................24
创建Python类...................................................................................................................24
添加属性.............................................................................................................................26
让类实际做一些事情........................................................................................................26
对象的初始化.....................................................................................................................29
解释你自己.........................................................................................................................32
模块和包.............................................................................................................................34
组织模块.............................................................................................................................36
谁可以访问我的数据.........................................................................................................41
案例学习..........................................................................................................................43
练习..................................................................................................................................52
总结..................................................................................................................................53
第3章当对象是相似的...............................................................................................54
基本继承..........................................................................................................................54
扩展内置类......................................................................................................................56
重写和Super.....................................................................................................................58
多重继承..........................................................................................................................59
钻石的问题......................................................................................................................61
不同的参数集合..............................................................................................................66
多态..................................................................................................................................68
案例学习..........................................................................................................................71
练习..................................................................................................................................84
总结..................................................................................................................................85
第4章异常处理...........................................................................................................86
抛出异常..........................................................................................................................86
抛出一个异常..................................................................................................................88
当一个异常产生时发生了什么......................................................................................90
异常处理..........................................................................................................................91
异常层级..........................................................................................................................97
定义自己的异常..............................................................................................................98
异常不是例外..................................................................................................................99
案例学习.........................................................................................................................102
练习.................................................................................................................................112
总结.................................................................................................................................113
第5章何时使用面向对象编程..................................................................................114
把对象当作“对象”来对待..........................................................................................114
使用property为类中的数据添加行为.........................................................................118
property是怎样工作的..................................................................................................121
装饰器:创建property的另一种方法..........................................................................123
何时该使用property属性..............................................................................................125
管理对象...........................................................................................................................127
移除重复的代码................................................................................................................130
实践一下...........................................................................................................................131
或者我们可以使用组合....................................................................................................135
案例学习...........................................................................................................................137
练习...................................................................................................................................145
总结...................................................................................................................................146
第6章Python数据结构...............................................................................................147
空对象...............................................................................................................................147
元组和命名元组...............................................................................................................148
命名元组...........................................................................................................................150
字典...................................................................................................................................152
何时应该使用字典...........................................................................................................155
使用defaultdict.................................................................................................................156
列表..................................................................................................................................157
对列表排序......................................................................................................................160
集合..................................................................................................................................162
扩展内置数据类型..........................................................................................................166
案例学习..........................................................................................................................171
练习..................................................................................................................................178
总结..................................................................................................................................178
第7章Python里面向对象的快捷方式......................................................................180
Python内置函数.............................................................................................................180
Len......................................................................................................................................180
Reversed.............................................................................................................................181
Enumerate..........................................................................................................................182
Zip.......................................................................................................................................183
其他函数...........................................................................................................................185
解析...................................................................................................................................186
列表解析...........................................................................................................................186
集合和字典解析...............................................................................................................188
生成器表达式...................................................................................................................189
生成器...............................................................................................................................191
方法重载的另一种选择...................................................................................................194
默认参数...........................................................................................................................195
可变参数列表...................................................................................................................197
参数拆分...........................................................................................................................201
函数也是对象...................................................................................................................202
使用函数作为属性...........................................................................................................206
可调用对象.......................................................................................................................207
案例学习...........................................................................................................................208
练习...................................................................................................................................212
总结...................................................................................................................................213
第8章设计模式1..........................................................................................................214
设计模式...........................................................................................................................214
装饰器模式.......................................................................................................................215
装饰器实例.......................................................................................................................216
Python中的装饰器模式.................................................................................................219
观察者模式......................................................................................................................221
观察者实例......................................................................................................................222
策略模式..........................................................................................................................224
策略实例..........................................................................................................................225
Python中的策略模式.....................................................................................................226
状态模式..........................................................................................................................227
状态实例..........................................................................................................................227
状态和策略模式的对比...................................................................................................233
单件模式..........................................................................................................................234
单件的实现方式..............................................................................................................234
模块变量能够模仿单件..................................................................................................235
模板模式.........................................................................................................................238
模板实例.........................................................................................................................238
练习.................................................................................................................................242
总结.................................................................................................................................243
第9章设计模式2........................................................................................................244
适配器模式.....................................................................................................................244
外观模式.........................................................................................................................247
享元模式.........................................................................................................................250
命令模式.........................................................................................................................254
抽象工厂模式.................................................................................................................259
组合模式.........................................................................................................................263
练习.................................................................................................................................267
总结.................................................................................................................................268
第10章文件和字符串................................................................................................270
字符串.............................................................................................................................270
字符串操作.....................................................................................................................271
字符串格式化.................................................................................................................274
字符串是Unicode的....................................................................................................281
可变字节字符串............................................................................................................285
文件I/O...........................................................................................................................286
把它放在上下文............................................................................................................287
伪造文件.......................................................................................................................289
存储对象.......................................................................................................................290
定制pickle......................................................................................................................292
序列化Web对象.........................................................................................................294
练习...............................................................................................................................297
总结...............................................................................................................................299
第11章测试面向对象的程序..................................................................................300
为什么要测试...............................................................................................................300
测试驱动开发...............................................................................................................302
单元测试.......................................................................................................................303
断言方法.......................................................................................................................304
减少样板和清理...........................................................................................................306
组织和运行测试...........................................................................................................308
忽略失败的测试...........................................................................................................309
用py.test测试.............................................................................................................311
一个处理安装和清理的方法.......................................................................................313
一种完全不同的变量设置方式...................................................................................316
用py.test跳过测试.....................................................................................................320
py.test的补充..............................................................................................................321
多少测试才算够..........................................................................................................323
案例学习......................................................................................................................326
实现它.......................................................................................................................327
练习..........................................................................................................................332
总结..........................................................................................................................333
第12章常用Python3库....................................................................................334
数据库访问..............................................................................................................335
引入SQLAlchemy......................................................................................................336
漂亮的用户界面......................................................................................................340
TkInter........................................................................................................................341
PyQt...........................................................................................................................345
选择一个GUI工具包.............................................................................................347
XML............................................................................................................................348
ElementTree...............................................................................................................349
Lxml...........................................................................................................................353
CherryPy....................................................................................................................354
一个完整的Web堆栈...........................................................................................357
练习.........................................................................................................................363
总结.........................................................................................................................364