第 1章 使用Python模塊\t1
1.1 介紹\t1
1.2 使用和導(dǎo)入模塊以及命名空間\t2
1.2.1 實(shí)現(xiàn)方法\t3
1.2.2 工作原理\t5
1.2.3 擴(kuò)展知識(shí)\t6
1.3 實(shí)現(xiàn)Python虛擬環(huán)境\t9
1.3.1 準(zhǔn)備工作\t10
1.3.2 實(shí)現(xiàn)方法\t12
1.3.3 工作原理\t13
1.3.4 擴(kuò)展知識(shí)\t13
1.4 Python包安裝選項(xiàng)\t13
1.4.1 實(shí)現(xiàn)方法\t14
1.4.2 工作原理\t15
1.5 利用需求文件并解決沖突\t15
1.5.1 實(shí)現(xiàn)方法\t16
1.5.2 工作原理\t17
1.5.3 擴(kuò)展知識(shí)\t17
1.6 使用本地補(bǔ)丁和約束文件\t17
1.6.1 實(shí)現(xiàn)方法\t18
1.6.2 工作原理\t19
1.6.3 擴(kuò)展知識(shí)\t19
1.7 使用包\t20
1.7.1 實(shí)現(xiàn)方法\t20
1.7.2 工作原理\t21
1.7.3 擴(kuò)展知識(shí)\t22
1.8 創(chuàng)建wheel和bundle\t22
1.8.1 實(shí)現(xiàn)方法\t23
1.8.2 工作原理\t23
1.8.3 擴(kuò)展知識(shí)\t24
1.9 源代碼與字節(jié)碼的比較\t24
1.9.1 實(shí)現(xiàn)方法\t24
1.9.2 工作原理\t25
1.9.3 擴(kuò)展知識(shí)\t25
1.10 如何創(chuàng)建和引用模塊包\t25
1.10.1 實(shí)現(xiàn)方法\t26
1.10.2 工作原理\t27
1.10.3 擴(kuò)展知識(shí)\t27
1.11 操作系統(tǒng)專用二進(jìn)制文件\t28
1.11.1 實(shí)現(xiàn)方法\t30
1.11.2 擴(kuò)展知識(shí)\t33
1.12 如何上傳程序到PyPI\t33
1.12.1 準(zhǔn)備工作\t34
1.12.2 實(shí)現(xiàn)方法\t34
1.12.3 工作原理\t34
1.13 項(xiàng)目打包\t37
1.14 上傳到PyPI\t39
1.14.1 準(zhǔn)備工作\t39
1.14.2 實(shí)現(xiàn)方法\t39
1.14.3 工作原理\t40
第 2章 使用Python解釋器\t41
2.1 介紹\t41
2.2 登錄Python環(huán)境\t42
2.2.1 實(shí)現(xiàn)方法\t42
2.2.2 工作原理\t42
2.3 利用Python命令選項(xiàng)\t43
2.3.1 實(shí)現(xiàn)方法\t43
2.3.2 工作原理\t44
2.3.3 接口選項(xiàng)\t44
2.3.4 通用選項(xiàng)\t45
2.3.5 雜項(xiàng)選項(xiàng)\t45
2.4 處理環(huán)境變量\t47
2.4.1 實(shí)現(xiàn)方法\t48
2.4.2 工作原理\t48
2.5 使腳本可執(zhí)行\(zhòng)t51
2.5.1 實(shí)現(xiàn)方法\t51
2.5.2 擴(kuò)展知識(shí)\t51
2.6 修改交互式解釋器的啟動(dòng)文件\t52
2.7 Python的其他實(shí)現(xiàn)方法\t52
2.7.1 實(shí)現(xiàn)方法\t53
2.7.2 擴(kuò)展知識(shí)\t54
2.8 在Windows操作系統(tǒng)上安裝Python\t55
2.8.1 準(zhǔn)備工作\t56
2.8.2 實(shí)現(xiàn)方法\t56
2.9 使用基于Windows操作系統(tǒng)的Python啟動(dòng)器\t57
2.10 將Python嵌入其他應(yīng)用程序\t58
2.10.1 實(shí)現(xiàn)方法\t58
2.10.2 工作原理\t59
2.11 Python Shell的替代品—IPython\t60
2.11.1 準(zhǔn)備工作\t61
2.11.2 實(shí)現(xiàn)方法\t62
2.11.3 擴(kuò)展知識(shí)\t64
2.12 Python Shell的替代品—bpython\t64
2.12.1 準(zhǔn)備工作\t65
2.12.2 實(shí)現(xiàn)方法\t65
2.12.3 擴(kuò)展知識(shí)\t66
2.13 Python Shell的替代品—DreamPie\t66
2.13.1 準(zhǔn)備工作\t67
2.13.2 實(shí)現(xiàn)方法\t67
2.13.3 擴(kuò)展知識(shí)\t67
第3章 使用裝飾器\t68
3.1 介紹\t68
3.2 回顧函數(shù)\t69
3.2.1 實(shí)現(xiàn)方法\t69
3.2.2 工作原理\t71
3.3 裝飾器簡介\t71
3.3.1 實(shí)現(xiàn)方法\t72
3.3.2 工作原理\t74
3.4 使用函數(shù)裝飾器\t74
3.4.1 實(shí)現(xiàn)方法\t75
3.4.2 工作原理\t76
3.5 使用類裝飾器\t78
3.6 裝飾器示例\t81
3.6.1 準(zhǔn)備工作\t82
3.6.2 實(shí)現(xiàn)方法\t82
3.6.3 工作原理\t85
3.6.4 擴(kuò)展知識(shí)\t86
3.7 使用裝飾器模塊\t89
3.7.1 實(shí)現(xiàn)方法\t90
3.7.2 工作原理\t92
3.7.3 擴(kuò)展知識(shí)\t92
第4章 使用Python collections\t93
4.1 介紹\t93
4.2 回顧容器\t94
4.2.1 實(shí)現(xiàn)方法\t94
4.2.2 擴(kuò)展知識(shí)\t96
4.3 實(shí)現(xiàn)namedtuple\t99
4.3.1 實(shí)現(xiàn)方法\t100
4.3.2 擴(kuò)展知識(shí)\t102
4.4 實(shí)現(xiàn)雙端隊(duì)列\(zhòng)t105
4.5 實(shí)現(xiàn)ChainMap\t110
4.6 實(shí)現(xiàn)計(jì)數(shù)器\t114
4.6.1 實(shí)現(xiàn)方法\t114
4.6.2 擴(kuò)展知識(shí)\t117
4.7 實(shí)現(xiàn)OrderedDict\t117
4.8 實(shí)現(xiàn)defaultdict\t121
4.9 實(shí)現(xiàn)UserDict\t124
4.10 實(shí)現(xiàn)UserList\t125
4.10.1 實(shí)現(xiàn)方法\t126
4.10.2 擴(kuò)展知識(shí)\t127
4.11 實(shí)現(xiàn)UserString\t127
4.12 優(yōu)化Python collections\t128
4.13 窺探collections-extended模塊\t135
4.13.1 準(zhǔn)備工作\t136
4.13.2 實(shí)現(xiàn)方法\t137
第5章 生成器、協(xié)同程序和并行處理\t143
5.1 介紹\t143
5.2 Python中的迭代是如何工作的\t144
5.3 使用itertools模塊\t148
5.4 使用生成器函數(shù)\t165
5.4.1 實(shí)現(xiàn)方法\t165
5.4.2 工作原理\t166
5.4.3 擴(kuò)展知識(shí)\t167
5.5 使用協(xié)同程序模擬多線程\t168
5.5.1 實(shí)現(xiàn)方法\t169
5.5.2 擴(kuò)展知識(shí)\t171
5.6 何時(shí)使用并行處理\t172
5.6.1 實(shí)現(xiàn)方法\t172
5.6.2 擴(kuò)展知識(shí)\t173
5.7 Fork進(jìn)程\t173
5.7.1 實(shí)現(xiàn)方法\t174
5.7.2 工作原理\t174
5.7.3 擴(kuò)展知識(shí)\t175
5.8 如何實(shí)現(xiàn)多線程\t175
5.8.1 實(shí)現(xiàn)方法\t176
5.8.2 擴(kuò)展知識(shí)\t180
5.9 如何實(shí)現(xiàn)多進(jìn)程\t181
5.9.1 實(shí)現(xiàn)方法\t182
5.9.2 擴(kuò)展知識(shí)\t184
第6章 使用Python的math模塊\t186
6.1 介紹\t186
6.2 使用math模塊的函數(shù)和常量\t187
6.3 處理復(fù)數(shù)\t202
6.4 改善小數(shù)\t205
6.5 提高分?jǐn)?shù)精度\t209
6.6 處理隨機(jī)數(shù)\t210
6.7 使用secrets模塊\t215
6.8 實(shí)現(xiàn)基本統(tǒng)計(jì)操作\t216
6.9 使用comath改進(jìn)功能\t221
6.9.1 準(zhǔn)備工作\t221
6.9.2 實(shí)現(xiàn)方法\t221
第7章 使用PyPy提升Python性能\t225
7.1 介紹\t225
7.2 什么是PyPy\t226
7.2.1 準(zhǔn)備工作\t227
7.2.2 實(shí)現(xiàn)方法\t228
7.2.3 擴(kuò)展知識(shí)\t232
7.3 什么是RPython\t233
7.3.1 實(shí)現(xiàn)方法\t233
7.3.2 擴(kuò)展知識(shí)\t235
7.4 現(xiàn)實(shí)示例\t235
7.4.1 實(shí)現(xiàn)方法\t236
7.4.2 擴(kuò)展知識(shí)\t241
第8章 Python增強(qiáng)方案\t242
8.1 介紹\t242
8.2 PEP\t242
8.2.1 實(shí)現(xiàn)方法\t243
8.2.2 擴(kuò)展知識(shí)\t245
8.3 PEP 556—線程垃圾回收\t246
8.3.1 準(zhǔn)備工作\t246
8.3.2 實(shí)現(xiàn)方法\t247
8.3.3 擴(kuò)展知識(shí)\t251
8.4 PEP 554—多個(gè)子解釋器\t252
8.4.1 實(shí)現(xiàn)方法\t252
8.4.2 工作原理\t256
8.4.3 擴(kuò)展知識(shí)\t257
8.5 PEP 551—安全透明度\t258
8.5.1 準(zhǔn)備工作\t258
8.5.2 實(shí)現(xiàn)方法\t259
8.6 PEP 543—統(tǒng)一的TLS API\t261
8.6.1 實(shí)現(xiàn)方法\t262
8.6.2 擴(kuò)展知識(shí)\t263
第9章 使用LyX寫文檔\t264
9.1 介紹\t264
9.2 Python文檔工具和技術(shù)\t265
9.3 行內(nèi)注釋和dir命令\t266
9.4 使用文檔字符串\t268
9.4.1 實(shí)現(xiàn)方法\t269
9.4.2 擴(kuò)展知識(shí)\t274
9.5 使用PyDoc幫助\t277
9.6 HTML報(bào)告\t278
9.7 使用reStructuredText文件\t282
9.7.1 準(zhǔn)備工作\t283
9.7.2 實(shí)現(xiàn)方法\t283
9.8 使用Sphinx文檔程序\t286
9.8.1 準(zhǔn)備工作\t286
9.8.2 實(shí)現(xiàn)方法\t286
9.9 使用LaTeX和LyX文檔編寫程序\t293
9.9.1 準(zhǔn)備工作\t294
9.9.2 實(shí)現(xiàn)方法\t294
9.9.3 擴(kuò)展知識(shí)\t299