關(guān)于我們
書(shū)單推薦
新書(shū)推薦
|
Python精粹(英文版) 讀者對(duì)象:本書(shū)適合Python程序員及相關(guān)科技人員、工程師、軟件專(zhuān)業(yè)人士閱讀。
這是一本關(guān)于Python編程的書(shū)。它并未覆蓋Python的方方面面,其重點(diǎn)是呈現(xiàn)現(xiàn)代且精選的Python語(yǔ)言核心,即側(cè)重于Python編程本身。本書(shū)包括抽象實(shí)現(xiàn)、程序結(jié)構(gòu)、數(shù)據(jù)、函數(shù)、對(duì)象、模塊等主題,這些主題能夠有效幫助Python程序員應(yīng)對(duì)各種項(xiàng)目規(guī)模的挑戰(zhàn)。同時(shí),本書(shū)通常會(huì)省略那些完全可以通過(guò)IDE輕松獲取的參考內(nèi)容(例如函數(shù)列表、命令名稱(chēng)、參數(shù)等),并特意不去描述Python編輯器工具、IDE、部署等快速變化的內(nèi)容及相關(guān)問(wèn)題。
大衛(wèi)·M.比茲利是Python Essential Reference,Fourth Edition(Addison-Wesley,2010年出版)和Python Cookbook,Third Edition(O‘Reilly,2013年出版)的作者。他目前在自己的公司Dabeaz LLC教授高級(jí)計(jì)算機(jī)科學(xué)課程。自1996年以來(lái),他一直在使用及教授Python,并進(jìn)行Python方面的寫(xiě)作及演講。
1 Python 基礎(chǔ) .................................................................................. 15
1.1 運(yùn)行 Python .............................................................................................................. 15 1.2 Python 程序 .............................................................................................................. 16 1.3 基本類(lèi)型、變量與表達(dá)式 ...................................................................................... 17 1.4 算術(shù)運(yùn)算符 .............................................................................................................. 19 1.5 條件與控制流 .......................................................................................................... 21 1.6 文本串 ...................................................................................................................... 23 1.7 文件輸入與輸出 ...................................................................................................... 26 1.8 列表 .......................................................................................................................... 27 1.9 元組 .......................................................................................................................... 29 1.10 Set ........................................................................................................................... 31 1.11 字典 ........................................................................................................................ 32 1.12 迭代與循環(huán) ............................................................................................................ 35 1.13 函數(shù) ........................................................................................................................ 36 1.14 異常 ........................................................................................................................ 38 1.15 程序終止 ................................................................................................................ 40 1.16 對(duì)象和類(lèi) ................................................................................................................ 40 1.17 模塊 ........................................................................................................................ 44 1.18 腳本編寫(xiě) ................................................................................................................ 46 1.19 包 ............................................................................................................................ 47 1.20 構(gòu)建應(yīng)用程序 ........................................................................................................ 48 1.21 第三方包管理 ........................................................................................................ 49 1.22 Python 讓人感到舒適 ............................................................................................ 50 2 運(yùn)算符、表達(dá)式和數(shù)據(jù)操作 ................................................................. 51 2.1 字面量 ...................................................................................................................... 51 2.2 表達(dá)式與地址 .......................................................................................................... 52 2.3 標(biāo)準(zhǔn)運(yùn)算符 .............................................................................................................. 53 2.4 就地賦值 .................................................................................................................. 55 2.5 對(duì)象比較 .................................................................................................................. 56 2.6 有序比較運(yùn)算符 ...................................................................................................... 56 2.7 布爾表達(dá)式及真值 .................................................................................................. 57 2.8 條件表達(dá)式 .............................................................................................................. 58 2.9 迭代操作 .................................................................................................................. 59 2.10 序列操作 ................................................................................................................ 61 2.11 可變序列操作 ........................................................................................................ 63 2.12 Set 操作 .................................................................................................................. 64 2.13 映射操作 ................................................................................................................ 65 2.14 列表、Set 與字典解析式 ...................................................................................... 66 2.15 生成器表達(dá)式 ........................................................................................................ 68 2.16 特性(.)運(yùn)算符 ................................................................................................... 70 2.17 函數(shù)調(diào)用()運(yùn)算符 ................................................................................................. 70 2.18 求值順序 ................................................................................................................ 70 2.19 最后的話(huà):數(shù)據(jù)的秘密 ........................................................................................ 72 3 程序結(jié)構(gòu)與控制流 ............................................................................ 73 3.1 程序結(jié)構(gòu)與執(zhí)行 ...................................................................................................... 73 3.2 條件執(zhí)行 .................................................................................................................. 73 3.3 循環(huán)與迭代 .............................................................................................................. 74 3.4 異常 .......................................................................................................................... 78 3.4.1 異常層次 ..................................................................................................... 81 3.4.2 異常與控制流 ............................................................................................. 82 3.4.3 定義新異常 ................................................................................................. 83 3.4.4 鏈?zhǔn)疆惓?..................................................................................................... 84 3.4.5 異;厮 ..................................................................................................... 87 3.4.6 異常處理建議 ............................................................................................. 87 3.5 上下文管理器和 with 語(yǔ)句 ..................................................................................... 89 3.6 斷言和__debug__ .................................................................................................... 91 3.7 最后的話(huà) .................................................................................................................. 92 4 對(duì)象、類(lèi)型和協(xié)議 ............................................................................ 93 4.1 核心概念 .................................................................................................................. 93 4.2 對(duì)象標(biāo)識(shí)與類(lèi)型 ...................................................................................................... 94 4.3 引用計(jì)數(shù)與垃圾回收 .............................................................................................. 95 4.4 引用與復(fù)制 .............................................................................................................. 97 4.5 對(duì)象的表示與打印 .................................................................................................. 98 4.6 頭等對(duì)象 .................................................................................................................. 99 4.7 對(duì)可選的或缺失的數(shù)據(jù)使用 None ....................................................................... 101 4.8 對(duì)象協(xié)議及數(shù)據(jù)抽象 ............................................................................................ 101 4.9 對(duì)象協(xié)議 ................................................................................................................ 103 4.10 數(shù)字協(xié)議 .............................................................................................................. 104 4.11 比較協(xié)議 .............................................................................................................. 106 4.12 轉(zhuǎn)換協(xié)議 .............................................................................................................. 108 4.13 容器協(xié)議 .............................................................................................................. 109 4.14 迭代協(xié)議 .............................................................................................................. 111 4.15 特性協(xié)議 .............................................................................................................. 112 4.16 函數(shù)協(xié)議 .............................................................................................................. 112 4.17 上下文管理器協(xié)議 .............................................................................................. 113 4.18 最后的話(huà):關(guān)于 Pythonic ................................................................................... 113 5 函數(shù) ........................................................................................... 115 5.1 函數(shù)定義 ................................................................................................................ 115 5.2 缺省參數(shù) ................................................................................................................ 115 5.3 可變參數(shù) ................................................................................................................ 116 5.4 關(guān)鍵字參數(shù) ............................................................................................................ 117 5.5 可變關(guān)鍵字參數(shù) .................................................................................................... 118 5.6 接受所有輸入的函數(shù) ............................................................................................ 118 5.7 位置限定(Positional-Only)參數(shù) ....................................................................... 119 5.8 名稱(chēng)、文檔字符串和類(lèi)型提示 ............................................................................ 120 5.9 函數(shù)應(yīng)用及參數(shù)傳遞 ............................................................................................ 121 5.10 返回值 .................................................................................................................. 123 5.11 錯(cuò)誤處理 .............................................................................................................. 124 5.12 作用域規(guī)則 .......................................................................................................... 125 5.13 遞歸 ...................................................................................................................... 128 5.14 lambda 表達(dá)式 ..................................................................................................... 128 5.15 高階函數(shù) .............................................................................................................. 129 5.16 回調(diào)函數(shù)中的參數(shù)傳遞 ...................................................................................... 132 5.17 從回調(diào)函數(shù)返回結(jié)果 .......................................................................................... 135 5.18 裝飾器 .................................................................................................................. 138 5.19 map、filter 和 reduce ........................................................................................... 141 5.20 函數(shù)自省、特性和簽名 ...................................................................................... 143 5.21 環(huán)境檢查 .............................................................................................................. 145 5.22 動(dòng)態(tài)代碼的執(zhí)行和創(chuàng)建 ...................................................................................... 147 5.23 異步函數(shù)和 await ................................................................................................ 149 5.24 最后的話(huà):函數(shù)與組合的思考 .......................................................................... 151 6 生成器 ........................................................................................ 153 6.1 生成器與 yield ....................................................................................................... 153 6.2 可重新啟動(dòng)的生成器 ............................................................................................ 156 6.3 生成器委托 ............................................................................................................ 156 6.4 生成器實(shí)踐 ............................................................................................................ 158 6.5 增強(qiáng)型生成器和 yield 表達(dá)式 .............................................................................. 160 6.6 增強(qiáng)型生成器的應(yīng)用 ............................................................................................ 162 6.7 生成器與 await 的聯(lián)系 ......................................................................................... 165 6.8 最后的話(huà):生成器簡(jiǎn)史及展望 ............................................................................ 166 7 類(lèi)和面向?qū)ο缶幊?.......................................................................... 167 7.1 對(duì)象 ........................................................................................................................ 167 7.2 class 語(yǔ)句 ............................................................................................................... 168 7.3 實(shí)例 ........................................................................................................................ 169 7.4 特性訪(fǎng)問(wèn) ................................................................................................................ 170 7.5 作用域規(guī)則 ............................................................................................................ 172 7.6 運(yùn)算符重載及協(xié)議 ................................................................................................ 173 7.7 繼承 ........................................................................................................................ 174 7.8 通過(guò)組合避免繼承 ................................................................................................ 177 7.9 通過(guò)函數(shù)避免繼承 ................................................................................................ 180 7.10 動(dòng)態(tài)綁定和鴨子類(lèi)型 .......................................................................................... 181 7.11 繼承內(nèi)置類(lèi)型的危險(xiǎn)性 ...................................................................................... 181 7.12 類(lèi)變量和方法 ...................................................................................................... 183 7.13 靜態(tài)方法 .............................................................................................................. 187 7.14 略談設(shè)計(jì)模式 ...................................................................................................... 190 7.15 數(shù)據(jù)封裝和私有特性 .......................................................................................... 190 7.16 類(lèi)型提示 .............................................................................................................. 193 7.17 屬性 ...................................................................................................................... 194 7.18 類(lèi)型、接口和抽象基類(lèi) ...................................................................................... 197 7.19 多重繼承、接口和 mixin .................................................................................... 201 7.20 基于類(lèi)型的分派 .................................................................................................. 207 7.21 類(lèi)裝飾器 .............................................................................................................. 208 7.22 有監(jiān)督的繼承 ...................................................................................................... 211 7.23 對(duì)象生命周期與內(nèi)存管理 .................................................................................. 213 7.24 弱引用 .................................................................................................................. 218 7.25 內(nèi)部對(duì)象表示和特性綁定 .................................................................................. 220 7.26 代理、包裝器和委托 .......................................................................................... 222 7.27 使用__slots__減少內(nèi)存 ....................................................................................... 224 7.28 描述符 .................................................................................................................. 225 7.29 類(lèi)定義過(guò)程 .......................................................................................................... 229 7.30 動(dòng)態(tài)創(chuàng)建類(lèi) .......................................................................................................... 230 7.31 元類(lèi) ...................................................................................................................... 231 7.32 用于實(shí)例和類(lèi)的內(nèi)置對(duì)象 .................................................................................. 236 7.33 最后的話(huà):保持簡(jiǎn)單 .......................................................................................... 237 8 模塊和包 ..................................................................................... 239 8.1 模塊和 import 語(yǔ)句 ............................................................................................... 239 8.2 模塊緩存 ................................................................................................................ 241 8.3 從模塊導(dǎo)入選定名稱(chēng) ............................................................................................ 242 8.4 循環(huán)導(dǎo)入 ................................................................................................................ 244 8.5 模塊的重新加載與卸載 ........................................................................................ 246 8.6 模塊編譯 ................................................................................................................ 247 8.7 模塊搜索路徑 ........................................................................................................ 248 8.8 作為主程序執(zhí)行 .................................................................................................... 248 8.9 包 ............................................................................................................................ 249 8.10 包內(nèi)導(dǎo)入 .............................................................................................................. 251 8.11 以腳本方式運(yùn)行包的子模塊 .............................................................................. 252 8.12 控制包命名空間 .................................................................................................. 253 8.13 控制包的導(dǎo)出 ...................................................................................................... 254 8.14 包數(shù)據(jù) .................................................................................................................. 255 8.15 模塊對(duì)象 .............................................................................................................. 256 8.16 部署 Python 包 ..................................................................................................... 257 8.17 倒數(shù)第二句話(huà):從一個(gè)包開(kāi)始 .......................................................................... 258 8.18 最后的話(huà):保持簡(jiǎn)單 .......................................................................................... 259 9 輸入與輸出 .................................................................................. 261 9.1 數(shù)據(jù)表示 ................................................................................................................ 261 9.2 文本編碼和解碼 .................................................................................................... 262 9.3 文本和字節(jié)格式化 ................................................................................................ 264 9.4 讀取命令行選項(xiàng) .................................................................................................... 268 9.5 環(huán)境變量 ................................................................................................................ 270 9.6 文件和文件對(duì)象 .................................................................................................... 270 9.6.1 文件名稱(chēng) ................................................................................................... 271 9.6.2 文件模式 ................................................................................................... 272 9.6.3 I/O 緩沖 ..................................................................................................... 272 9.6.4 文本模式編碼 ........................................................................................... 273 9.6.5 文本模式行處理 ....................................................................................... 274 9.7 I/O 抽象層 .............................................................................................................. 274 9.7.1 文件方法 ................................................................................................... 275 9.8 標(biāo)準(zhǔn)輸入、輸出和錯(cuò)誤 ........................................................................................ 277 9.9 目錄 ........................................................................................................................ 278 9.10 print()函數(shù) ............................................................................................................ 279 9.11 生成輸出 .............................................................................................................. 279 9.12 消費(fèi)輸入 .............................................................................................................. 280 9.13 對(duì)象序列化 .......................................................................................................... 282 9.14 阻塞操作和并發(fā) .................................................................................................. 283 9.14.1 非阻塞 I/O ............................................................................................... 284 9.14.2 I/O 輪詢(xún) ................................................................................................... 285 9.14.3 線(xiàn)程 ......................................................................................................... 285 9.14.4 使用 asyncio 并發(fā)執(zhí)行 ........................................................................... 286 9.15 標(biāo)準(zhǔn)庫(kù)模塊 .......................................................................................................... 287 9.15.1 asyncio 模塊 ............................................................................................ 287 9.15.2 binascii 模塊 ............................................................................................ 288 9.15.3 cgi 模塊 ................................................................................................... 289 9.15.4 configparser 模塊 .................................................................................... 209 9.15.5 csv 模塊 ................................................................................................... 209 9.15.6 errno 模塊 ................................................................................................ 291 9.15.7 fcntl 模塊 ................................................................................................. 292 9.15.8 hashlib 模塊 ............................................................................................. 292 9.15.9 http 包 ...................................................................................................... 293 9.15.10 io 模塊 ................................................................................................... 293 9.15.11 json 模塊 ................................................................................................ 294 9.15.12 logging 模塊 .......................................................................................... 294 9.15.13 os 模塊................................................................................................... 295 9.15.14 os.path 模塊 ........................................................................................... 295 9.15.15 pathlib 模塊 ........................................................................................... 296 9.15.16 re 模塊 ................................................................................................... 297 9.15.17 shutil 模塊 ............................................................................................. 298 9.15.18 select 模塊 ............................................................................................. 298 9.15.19 smtplib 模塊 .......................................................................................... 299 9.15.20 socket 模塊 ............................................................................................ 300 9.15.21 struct 模塊 ............................................................................................. 302 9.15.22 subprocess 模塊 ..................................................................................... 302 9.15.23 tempfile 模塊 ......................................................................................... 303 9.15.24 textwrap 模塊 ........................................................................................ 304 9.15.25 threading 模塊 ....................................................................................... 305 9.15.26 time 模塊 ............................................................................................... 307 9.15.27 urllib 包 ................................................................................................. 307 9.15.28 unicodedata 模塊 ................................................................................... 308 9.15.29 xml 包 .................................................................................................... 309 9.16 最后的話(huà) .............................................................................................................. 310 10 內(nèi)置函數(shù)和標(biāo)準(zhǔn)庫(kù) ........................................................................ 311 10.1 內(nèi)置函數(shù) .............................................................................................................. 311 10.2 內(nèi)置異常 .............................................................................................................. 328 10.2.1 異常基類(lèi) ................................................................................................. 328 10.2.2 異常特性 ................................................................................................. 328 10.2.3 預(yù)定義異常類(lèi) ......................................................................................... 329 10.3 標(biāo)準(zhǔn)庫(kù) .................................................................................................................. 332 10.3.1 collections 模塊 ....................................................................................... 332 10.3.2 datetime 模塊 .......................................................................................... 332 10.3.3 itertools 模塊 ........................................................................................... 332 10.3.4 inspect 模塊 ............................................................................................. 332 10.3.5 math 模塊 ................................................................................................ 332 10.3.6 os 模塊 .................................................................................................... 333 10.3.7 random 模塊 ............................................................................................ 333 10.3.8 re 模塊 ..................................................................................................... 333 10.3.9 shutil 模塊 ............................................................................................... 333 10.3.10 statistics 模塊 ........................................................................................ 333 10.3.11 sys 模塊 ................................................................................................. 333 10.3.12 time 模塊 ............................................................................................... 333 10.3.13 turtle 模塊 .............................................................................................. 333 10.3.14 unittest 模塊 .......................................................................................... 333 10.4 最后的話(huà):使用內(nèi)置功能 .................................................................................. 334
你還可能感興趣
我要評(píng)論
|