{"id":21177019,"url":"https://github.com/bat67/the-python-standard-library-by-example","last_synced_at":"2025-05-07T18:09:22.845Z","repository":{"id":51942214,"uuid":"188939450","full_name":"bat67/The-Python-Standard-Library-by-Example","owner":"bat67","description":"《Python3 标准库》电子书和配套代码 \"The Python Standard Library by Example\" ebook and source code 一本又厚又全的讲解Python3标准库的书籍（1000多页）适合当作字典参考或者闲暇时慢慢阅读。","archived":false,"fork":false,"pushed_at":"2022-10-25T15:04:46.000Z","size":4070,"stargazers_count":166,"open_issues_count":1,"forks_count":84,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-07T18:08:58.797Z","etag":null,"topics":["book","books","code","ebook","ebooks","example","python","python-3","python-library","python-standard-library","python3","source-code","standard-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bat67.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-28T02:28:23.000Z","updated_at":"2025-04-19T16:29:17.000Z","dependencies_parsed_at":"2023-01-20T14:30:10.751Z","dependency_job_id":null,"html_url":"https://github.com/bat67/The-Python-Standard-Library-by-Example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bat67%2FThe-Python-Standard-Library-by-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bat67%2FThe-Python-Standard-Library-by-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bat67%2FThe-Python-Standard-Library-by-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bat67%2FThe-Python-Standard-Library-by-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bat67","download_url":"https://codeload.github.com/bat67/The-Python-Standard-Library-by-Example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252931555,"owners_count":21827112,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["book","books","code","ebook","ebooks","example","python","python-3","python-library","python-standard-library","python3","source-code","standard-library"],"created_at":"2024-11-20T17:14:18.174Z","updated_at":"2025-05-07T18:09:22.786Z","avatar_url":"https://github.com/bat67.png","language":"Python","readme":"# The Python Standard Library by Example | Python3 标准库\n\n\u003e \"The Python Standard Library by Example\" ebook and source code\n\n\u003e《Python3 标准库》电子书和配套代码\n\n一本又厚又全的讲解Python3标准库的书籍（1000多页）！适合当作字典参考或者闲暇时慢慢阅读。\n\n电子书见本仓库中：`The Python Standard Library by Example.pdf`\n\nE-book: `The Python Standard Library by Example.pdf` in this repo\n\n\n## 中文版本\n\n![](.assets/cover_zh.jpg)\n\n\n## 中文目录\n\n\u003cdetails\u003e\n\u003csummary\u003e展开查看\u003c/summary\u003e\n\u003cpre\u003e\n\n* 译者序\n* 前言\n* 第1章 文本 1\n* 1.1 string：文本常量和模板 1\n* 1.1.1 函数 1\n* 1.1.2 模板 2\n* 1.1.3 高级模板 3\n* 1.1.4 Formatter 5\n* 1.1.5 常量 5\n* 1.2 textwrap：格式化文本段落 6\n* 1.2.1 示例数据 6\n* 1.2.2 填充段落 7\n* 1.2.3 去除现有的缩进 7\n* 1.2.4 结合dedent和fill 8\n* 1.2.5 缩进块 8\n* 1.2.6 悬挂缩进 10\n* 1.2.7 截断长文本 10\n* 1.3 re：正则表达式 11\n* 1.3.1 查找文本中的模式 11\n* 1.3.2 编译表达式 12\n* 1.3.3 多重匹配 13\n* 1.3.4 模式语法 14\n* 1.3.5 限制搜索 22\n* 1.3.6 用组解析匹配 24\n* 1.3.7 搜索选项 29\n* 1.3.8 前向或后向 35\n* 1.3.9 自引用表达式 38\n* 1.3.10 用模式修改字符串 42\n* 1.3.11 利用模式拆分 44\n* 1.4 difflib：比较序列 46\n* 1.4.1 比较文本体 47\n* 1.4.2 无用数据 49\n* 1.4.3 比较任意类型 50\n* 第2章 数据结构 52\n* 2.1 enum：枚举类型 53\n* 2.1.1 创建枚举 53\n* 2.1.2 迭代 53\n* 2.1.3 比较Enum 54\n* 2.1.4 唯一枚举值 55\n* 2.1.5 通过编程创建枚举 56\n* 2.1.6 非整数成员值 58\n* 2.2 collections：容器数据类型 60\n* 2.2.1 ChainMap：搜索多个字典 60\n* 2.2.2 Counter：统计可散列的对象 63\n* 2.2.3 defaultdict：缺少的键返回一个默认值 66\n* 2.2.4 deque：双端队列 67\n* 2.2.5 namedtuple：带命名字段的元组子类 70\n* 2.2.6 OrderedDict：记住向字典中增加键的顺序 74\n* 2.2.7 collections.abc：容器的抽象基类 76\n* 2.3 数组：固定类型数据序列 78\n* 2.3.1 初始化 78\n* 2.3.2 处理数组 79\n* 2.3.3 数组和文件 79\n* 2.3.4 候选字节顺序 80\n* 2.4 heapq：堆排序算法 81\n* 2.4.1 示例数据 81\n* 2.4.2 创建堆 82\n* 2.4.3 访问堆的内容 83\n* 2.4.4 堆的数据极值 85\n* 2.4.5 高效合并有序序列 85\n* 2.5 bisect：维护有序列表 86\n* 2.5.1 有序插入 86\n* 2.5.2 处理重复 87\n* 2.6 queue：线程安全的FIFO实现 88\n* 2.6.1 基本FIFO队列 88\n* 2.6.2 LIFO队列 89\n* 2.6.3 优先队列 89\n* 2.6.4 构建一个多线程播客客户程序 90\n* 2.7 struct：二进制数据结构 93\n* 2.7.1 函数与Struct类 93\n* 2.7.2 打包和解包 93\n* 2.7.3 字节序 94\n* 2.7.4 缓冲区 95\n* 2.8 weakref：对象的非永久引用 96\n* 2.8.1 引用 96\n* 2.8.2 引用回调 97\n* 2.8.3 最终化对象 98\n* 2.8.4 代理 100\n* 2.8.5 缓存对象 101\n* 2.9 copy：复制对象 103\n* 2.9.1 浅副本 103\n* 2.9.2 深副本 104\n* 2.9.3 定制复制行为 105\n* 2.9.4 深副本中的递归 106\n* 2.10 pprint：美观打印数据结构 107\n* 2.10.1 打印 108\n* 2.10.2 格式化 108\n* 2.10.3 任意类 109\n* 2.10.4 递归 110\n* 2.10.5 限制嵌套输出 110\n* 2.10.6 控制输出宽度 111\n* 第3章 算法 113\n* 3.1 functools：管理函数的工具 113\n* 3.1.1 修饰符 113\n* 3.1.2 比较 119\n* 3.1.3 缓存 122\n* 3.1.4 缩减数据集 125\n* 3.1.5 泛型函数 127\n* 3.2 itertools：迭代器函数 129\n* 3.2.1 合并和分解迭代器 129\n* 3.2.2 转换输入 132\n* 3.2.3 生成新值 133\n* 3.2.4 过滤 135\n* 3.2.5 数据分组 138\n* 3.2.6 合并输入 139\n* 3.3 operator：内置操作符的函数接口 144\n* 3.3.1 逻辑操作 144\n* 3.3.2 比较操作符 145\n* 3.3.3 算术操作符 145\n* 3.3.4 序列操作符 146\n* 3.3.5 原地操作符 148\n* 3.3.6 属性和元素“获取方法” 148\n* 3.3.7 结合操作符和定制类 150\n* 3.4 contextlib：上下文管理器工具 151\n* 3.4.1 上下文管理器API 151\n* 3.4.2 上下文管理器作为函数修饰符 153\n* 3.4.3 从生成器到上下文管理器 154\n* 3.4.4 关闭打开的句柄 156\n* 3.4.5 忽略异常 157\n* 3.4.6 重定向输出流 158\n* 3.4.7 动态上下文管理器栈 159\n* 第4章 日期和时间 166\n* 4.1 time：时钟时间 166\n* 4.1.1 比较时钟 166\n* 4.1.2 墙上时钟时间 167\n* 4.1.3 单调时钟 168\n* 4.1.4 处理器时钟时间 169\n* 4.1.5 性能计数器 170\n* 4.1.6 时间组成 170\n* 4.1.7 处理时区 171\n* 4.1.8 解析和格式化时间 172\n* 4.2 datetime：日期和时间值管理 174\n* 4.2.1 时间 174\n* 4.2.2 日期 175\n* 4.2.3 timedelta 177\n* 4.2.4 日期算术运算 178\n* 4.2.5 比较值 179\n* 4.2.6 结合日期和时间 179\n* 4.2.7 格式化和解析 180\n* 4.2.8 时区 182\n* 4.3 calendar：处理日期 183\n* 4.3.1 格式化示例 183\n* 4.3.2 本地化环境 185\n* 4.3.3 计算日期 186\n* 第5章 数学运算 188\n* 5.1 decimal：定点数和浮点数的数学运算 188\n* 5.1.1 Decimal 188\n* 5.1.2 格式化 189\n* 5.1.3 算术运算 190\n* 5.1.4 特殊值 191\n* 5.1.5 上下文 192\n* 5.2 fractions：有理数 196\n* 5.2.1 创建Fraction实例 197\n* 5.2.2 算术运算 198\n* 5.2.3 近似值 199\n* 5.3 random：伪随机数生成器 199\n* 5.3.1 生成随机数 200\n* 5.3.2 指定种子 200\n* 5.3.3 保存状态 201\n* 5.3.4 随机整数 202\n* 5.3.5 选择随机元素 203\n* 5.3.6 排列 203\n* 5.3.7 采样 205\n* 5.3.8 多个并发生成器 205\n* 5.3.9 SystemRandom 206\n* 5.3.10 非均匀分布 207\n* 5.4 math：数学函数 208\n* 5.4.1 特殊常量 208\n* 5.4.2 测试异常值 208\n* 5.4.3 比较 210\n* 5.4.4 将浮点值转换为整数 212\n* 5.4.5 浮点值的其他表示 213\n* 5.4.6 正号和负号 214\n* 5.4.7 常用计算 215\n* 5.4.8 指数和对数 218\n* 5.4.9 角 222\n* 5.4.10 三角函数 224\n* 5.4.11 双曲函数 226\n* 5.4.12 特殊函数 227\n* 5.5 statistics：统计计算 228\n* 5.5.1 平均值 228\n* 5.5.2 方差 230\n* 第6章 文件系统 232\n* 6.1 os.path：平台独立的文件名管理 233\n* 6.1.1 解析路径 233\n* 6.1.2 建立路径 236\n* 6.1.3 规范化路径 237\n* 6.1.4 文件时间 238\n* 6.1.5 测试文件 238\n* 6.2 pathlib：文件系统路径作为对象 240\n* 6.2.1 路径表示 240\n* 6.2.2 建立路径 240\n* 6.2.3 解析路径 242\n* 6.2.4 创建具体路径 243\n* 6.2.5 目录内容 244\n* 6.2.6 读写文件 246\n* 6.2.7 管理目录和符号链接 246\n* 6.2.8 文件类型 247\n* 6.2.9 文件属性 248\n* 6.2.10 权限 250\n* 6.2.11 删除 250\n* 6.3 glob：文件名模式匹配 252\n* 6.3.1 示例数据 252\n* 6.3.2 通配符 252\n* 6.3.3 单字符通配符 253\n* 6.3.4 字符区间 253\n* 6.3.5 转义元字符 254\n* 6.4 fnmatch：UNIX式glob模式匹配 254\n* 6.4.1 简单匹配 254\n* 6.4.2 过滤 255\n* 6.4.3 转换模式 256\n* 6.5 linecache：高效读取文本文件 257\n* 6.5.1 测试数据 257\n* 6.5.2 读取特定行 257\n* 6.5.3 处理空行 258\n* 6.5.4 错误处理 258\n* 6.5.5 读取Python源文件 259\n* 6.6 tempfile：临时文件系统对象 260\n* 6.6.1 临时文件 260\n* 6.6.2 命名文件 262\n* 6.6.3 假脱机文件 262\n* 6.6.4 临时目录 263\n* 6.6.5 预测名 264\n* 6.6.6 临时文件位置 264\n* 6.7 shutil：高层文件操作 265\n* 6.7.1 复制文件 265\n* 6.7.2 复制文件元数据 268\n* 6.7.3 处理目录树 269\n* 6.7.4 查找文件 271\n* 6.7.5 归档 272\n* 6.7.6 文件系统空间 275\n* 6.8 filecmp：比较文件 276\n* 6.8.1 示例数据 276\n* 6.8.2 比较文件 278\n* 6.8.3 比较目录 279\n* 6.8.4 在程序中使用差异 280\n* 6.9 mmap：内存映射文件 283\n* 6.9.1 读文件 284\n* 6.9.2 写文件 285\n* 6.9.3 正则表达式 286\n* 6.10 codecs：字符串编码和解码 287\n* 6.10.1 Unicode入门 287\n* 6.10.2 处理文件 289\n* 6.10.3 字节序 291\n* 6.10.4 错误处理 293\n* 6.10.5 编码转换 295\n* 6.10.6 非Unicode编码 296\n* 6.10.7 增量编码 297\n* 6.10.8 Unicode数据和网络通信 299\n* 6.10.9 定义定制编码 301\n* 6.11 io：文本、十进制和原始流I/O工具 307\n* 6.11.1 内存中的流 307\n* 6.11.2 为文本数据包装字节流 308\n* 第7章 数据持久存储与交换 310\n* 7.1 pickle：对象串行化 311\n* 7.1.1 编码和解码字符串中的数据 311\n* 7.1.2 处理流 312\n* 7.1.3 重构对象的问题 313\n* 7.1.4 不可腌制的对象 314\n* 7.1.5 循环引用 316\n* 7.2 shelve：对象的持久存储 318\n* 7.2.1 创建一个新shelf 318\n* 7.2.2 写回 319\n* 7.2.3 特定shelf类型 320\n* 7.3 dbm：UNIX键-值数据库 320\n* 7.3.1 数据库类型 321\n* 7.3.2 创建一个新数据库 321\n* 7.3.3 打开一个现有数据库 322\n* 7.3.4 错误情况 322\n* 7.4 sqlite3：嵌入式关系数据库 323\n* 7.4.1 创建数据库 323\n* 7.4.2 获取数据 326\n* 7.4.3 查询元数据 327\n* 7.4.4 行对象 328\n* 7.4.5 在查询中使用变量 329\n* 7.4.6 批量加载 331\n* 7.4.7 定义新的列类型 331\n* 7.4.8 确定列类型 334\n* 7.4.9 事务 336\n* 7.4.10 隔离级别 338\n* 7.4.11 内存中的数据库 341\n* 7.4.12 导出数据库内容 341\n* 7.4.13 在SQL中使用Python函数 342\n* 7.4.14 带正则表达式的查询 344\n* 7.4.15 定制聚集 345\n* 7.4.16 线程和连接共享 346\n* 7.4.17 限制对数据的访问 347\n* 7.5 xml.etree.ElementTree：XML操纵API 349\n* 7.5.1 解析XML文档 349\n* 7.5.2 遍历解析树 350\n* 7.5.3 查找文档中的节点 351\n* 7.5.4 解析节点属性 352\n* 7.5.5 解析时监视事件 354\n* 7.5.6 创建一个定制树构造器 356\n* 7.5.7 解析串 357\n* 7.5.8 用元素节点构造文档 359\n* 7.5.9 美观打印XML 359\n* 7.5.10 设置元素属性 360\n* 7.5.11 由节点列表构造树 362\n* 7.5.12 将XML串行化至一个流 364\n* 7.6 csv：逗号分隔值文件 366\n* 7.6.1 读文件 366\n* 7.6.2 写文件 367\n* 7.6.3 方言 368\n* 7.6.4 使用字段名 373\n* 第8章 数据压缩与归档 375\n* 8.1 zlib：GNU zlib压缩 375\n* 8.1.1 处理内存中的数据 375\n* 8.1.2 增量压缩与解压缩 377\n* 8.1.3 混合内容流 378\n* 8.1.4 校验和 378\n* 8.1.5 压缩网络数据 379\n* 8.2 gzip：读写GNU zip文件 382\n* 8.2.1 写压缩文件 382\n* 8.2.2 读压缩数据 384\n* 8.2.3 处理流 385\n* 8.3 bz2：bzip2压缩 386\n* 8.3.1 内存中的一次性操作 386\n* 8.3.2 增量压缩和解压缩 388\n* 8.3.3 混合内容流 388\n* 8.3.4 写压缩文件 389\n* 8.3.5 读压缩文件 390\n* 8.3.6 读写Unicode数据 391\n* 8.3.7 压缩网络数据 392\n* 8.4 tarfile：tar归档访问 395\n* 8.4.1 测试tar文件 396\n* 8.4.2 从归档读取元数据 396\n* 8.4.3 从归档抽取文件 397\n* 8.4.4 创建新归档 399\n* 8.4.5 使用候选归档成员名 399\n* 8.4.6 从非文件源写数据 400\n* 8.4.7 追加到归档 400\n* 8.4.8 处理压缩归档 401\n* 8.5 zipfile：ZIP归档访问 402\n* 8.5.1 测试ZIP文件 402\n* 8.5.2 从归档读取元数据 402\n* 8.5.3 从归档抽取归档文件 404\n* 8.5.4 创建新归档 404\n* 8.5.5 使用候选归档成员名 406\n* 8.5.6 从非文件源写数据 406\n* 8.5.7 利用ZipInfo实例写数据 407\n* 8.5.8 追加到文件 407\n* 8.5.9 Python ZIP归档 408\n* 8.5.10 限制 410\n* 第9章 加密 411\n* 9.1 hashlib：密码散列 411\n* 9.1.1 散列算法 411\n* 9.1.2 示例数据 412\n* 9.1.3 MD5示例 412\n* 9.1.4 SHA1示例 412\n* 9.1.5 按名创建散列 413\n* 9.1.6 增量更新 413\n* 9.2 hmac：密码消息签名与验证 414\n* 9.2.1 消息签名 415\n* 9.2.2 候选摘要类型 415\n* 9.2.3 二进制摘要 416\n* 9.2.4 消息签名的应用 416\n* 第 10 章 使用进程、线程和协程提供并发性 420\n* 10.1 subprocess：创建附加进程 420\n* 10.1.1 运行外部命令 421\n* 10.1.2 直接处理管道 425\n* 10.1.3 连接管道段 427\n* 10.1.4 与其他命令交互 428\n* 10.1.5 进程间传递信号 430\n* 10.2 signal：异步系统事件 434\n* 10.2.1 接收信号 434\n* 10.2.2 获取已注册的处理器 435\n* 10.2.3 发送信号 436\n* 10.2.4 闹铃 436\n* 10.2.5 忽略信号 437\n* 10.2.6 信号和线程 438\n* 10.3 threading：进程中管理并发操作 440\n* 10.3.1 Thread对象 440\n* 10.3.2 确定当前线程 441\n* 10.3.3 守护与非守护线程 442\n* 10.3.4 枚举所有线程 444\n* 10.3.5 派生线程 445\n* 10.3.6 定时器线程 447\n* 10.3.7 线程间传送信号 447\n* 10.3.8 控制资源访问 449\n* 10.3.9 同步线程 453\n* 10.3.10 限制资源的并发访问 456\n* 10.3.11 线程特定的数据 457\n* 10.4 multiprocessing：像线程一样管理进程 459\n* 10.4.1 multiprocessing基础 460\n* 10.4.2 可导入的目标函数 461\n* 10.4.3 确定当前进程 461\n* 10.4.4 守护进程 462\n* 10.4.5 等待进程 463\n* 10.4.6 终止进程 465\n* 10.4.7 进程退出状态 466\n* 10.4.8 日志 467\n* 10.4.9 派生进程 469\n* 10.4.10 向进程传递消息 469\n* 10.4.11 进程间信号传输 472\n* 10.4.12 控制资源访问 473\n* 10.4.13 同步操作 474\n* 10.4.14 控制资源的并发访问 475\n* 10.4.15 管理共享状态 476\n* 10.4.16 共享命名空间 477\n* 10.4.17 进程池 479\n* 10.4.18 实现MapReduce 480\n* 10.5 asyncio：异步I/O、事件循环和并发工具 484\n* 10.5.1 异步并发概念 484\n* 10.5.2 利用协程合作完成多任务 485\n* 10.5.3 调度常规函数调用 488\n* 10.5.4 异步地生成结果 490\n* 10.5.5 并发地执行任务 492\n* 10.5.6 组合协程和控制结构 495\n* 10.5.7 同步原语 499\n* 10.5.8 提供协议类抽象的异步I/O 505\n* 10.5.9 使用协程和流的异步I/O 510\n* 10.5.10 使用SSL 514\n* 10.5.11 与域名服务交互 516\n* 10.5.12 使用子进程 518\n* 10.5.13 接收UNIX信号 523\n* 10.5.14 结合使用协程、线程与进程 525\n* 10.5.15 用asyncio调试 527\n* 10.6 concurrent.futures：管理并发任务池 530\n* 10.6.1 利用基本线程池使用map() 531\n* 10.6.2 调度单个任务 532\n* 10.6.3 按任意顺序等待任务 532\n* 10.6.4 Future回调 533\n* 10.6.5 撤销任务 534\n* 10.6.6 任务中的异常 535\n* 10.6.7 上下文管理器 536\n* 10.6.8 进程池 537\n* 第 11 章 网络通信 539\n* 11.1 ipaddress：Internet地址 539\n* 11.1.1 地址 539\n* 11.1.2 网络 540\n* 11.1.3 接口 543\n* 11.2 socket：网络通信 544\n* 11.2.1 寻址、协议簇和套接字类型 544\n* 11.2.2 TCP/IP客户和服务器 552\n* 11.2.3 用户数据报客户和服务器 558\n* 11.2.4 UNIX域套接字 560\n* 11.2.5 组播 563\n* 11.2.6 发送二进制数据 566\n* 11.2.7 非阻塞通信和超时 568\n* 11.3 selectors：I/O多路复用抽象 568\n* 11.3.1 操作模型 569\n* 11.3.2 回送服务器 569\n* 11.3.3 回送客户 570\n* 11.3.4 服务器和客户 571\n* 11.4 select：高效等待I/O 572\n* 11.4.1 使用select() 572\n* 11.4.2 带超时的非阻塞I/O 577\n* 11.4.3 使用poll() 579\n* 11.4.4 平台特定的选项 582\n* 11.5 socketserver：创建网络服务器 583\n* 11.5.1 服务器类型 583\n* 11.5.2 服务器对象 583\n* 11.5.3 实现服务器 584\n* 11.5.4 请求处理器 584\n* 11.5.5 回送示例 584\n* 11.5.6 线程和进程 588\n* 第 12 章 互联网 592\n* 12.1 urllib.parse：分解URL 592\n* 12.1.1 解析 593\n* 12.1.2 反解析 595\n* 12.1.3 连接 596\n* 12.1.4 解码查询参数 597\n* 12.2 urllib.request：网络资源访问 599\n* 12.2.1 HTTP GET 599\n* 12.2.2 编码参数 600\n* 12.2.3 HTTP POST 601\n* 12.2.4 添加发出首部 602\n* 12.2.5 从请求提交表单数据 602\n* 12.2.6 上传文件 603\n* 12.2.7 创建定制协议处理器 606\n* 12.3 urllib.robotparser: Internet蜘蛛访问控制 * 608\n* 12.3.1 robots.txt 608\n* 12.3.2 测试访问权限 609\n* 12.3.3 长寿命蜘蛛 610\n* 12.4 base64：用ASCII编码二进制数据 611\n* 12.4.1 Base64编码 611\n* 12.4.2 Base64解码 612\n* 12.4.3 URL安全的变种 612\n* 12.4.4 其他编码 613\n* 12.5 http.server：实现Web服务器的基类 615\n* 12.5.1 HTTP GET 615\n* 12.5.2 HTTP POST 616\n* 12.5.3 线程和进程 618\n* 12.5.4 处理错误 619\n* 12.5.5 设置首部 620\n* 12.5.6 命令行用法 621\n* 12.6 http.cookies：HTTP cookie 622\n* 12.6.1 创建和设置cookie 622\n* 12.6.2 Morsel 622\n* 12.6.3 编码的值 624\n* 12.6.4 接收和解析Cookie首部 624\n* 12.6.5 候选输出格式 625\n* 12.7 webbrowser：显示Web页面 626\n* 12.7.1 简单示例 626\n* 12.7.2 窗口与标签页 626\n* 12.7.3 使用特定浏览器 627\n* 12.7.4 BROWSER变量 627\n* 12.7.5 命令行接口 627\n* 12.8 uuid：全局唯一标识符 628\n* 12.8.1 UUID 1：IEEE 802 MAC地址 628\n* 12.8.2 UUID 3和5：基于名字的值 630\n* 12.8.3 UUID 4：随机值 631\n* 12.8.4 处理UUID对象 631\n* 12.9 json：JavaScript对象记法 632\n* 12.9.1 编码和解码简单数据类型 633\n* 12.9.2 人类可读和紧凑输出 633\n* 12.9.3 编码字典 635\n* 12.9.4 处理定制类型 636\n* 12.9.5 编码器和解码器类 638\n* 12.9.6 处理流和文件 640\n* 12.9.7 混合数据流 641\n* 12.9.8 命令行上处理JSON 641\n* 12.10 xmlrpc.client：XML-RPC的客户库 642\n* 12.10.1 连接服务器 643\n* 12.10.2 数据类型 645\n* 12.10.3 传递对象 648\n* 12.10.4 二进制数据 648\n* 12.10.5 异常处理 650\n* 12.10.6 将调用组合在一个消息中 650\n* 12.11 xmlrpc.server：一个XML-RPC服务器 652\n* 12.11.1 一个简单的服务器 652\n* 12.11.2 候选API名 653\n* 12.11.3 加点的API名 654\n* 12.11.4 任意API名 655\n* 12.11.5 公布对象的方法 656\n* 12.11.6 分派调用 657\n* 12.11.7 自省API 659\n* 第 13 章 email 662\n* 13.1 smtplib：简单邮件传输协议客户 662\n* 13.1.1 发送email消息 662\n* 13.1.2 认证和加密 663\n* 13.1.3 验证email地址 666\n* 13.2 smtpd：示例邮件服务器 667\n* 13.2.1 邮件服务器基类 667\n* 13.2.2 调试服务器 669\n* 13.2.3 代理服务器 670\n* 13.3 mailbox：管理email归档 670\n* 13.3.1 mbox 671\n* 13.3.2 Maildir 673\n* 13.3.3 消息标志 678\n* 13.3.4 其他格式 680\n* 13.4 imaplib：IMAP4客户库 680\n* 13.4.1 变种 680\n* 13.4.2 连接服务器 681\n* 13.4.3 示例配置 682\n* 13.4.4 列出邮箱 682\n* 13.4.5 邮箱状态 684\n* 13.4.6 选择邮箱 686\n* 13.4.7 搜索消息 686\n* 13.4.8 搜索规则 687\n* 13.4.9 获取消息 689\n* 13.4.10 完整消息 693\n* 13.4.11 上传消息 694\n* 13.4.12 移动和复制消息 695\n* 13.4.13 删除消息 696\n* 第 14 章 应用构建模块 699\n* 14.1 argparse：命令行选项和参数解析 700\n* 14.1.1 建立解析器 700\n* 14.1.2 定义参数 700\n* 14.1.3 解析命令行 700\n* 14.1.4 简单示例 701\n* 14.1.5 帮助输出 707\n* 14.1.6 解析器组织 711\n* 14.1.7 高级参数处理 716\n* 14.2 getopt：命令行选项解析 722\n* 14.2.1 函数参数 722\n* 14.2.2 短格式选项 723\n* 14.2.3 长格式选项 723\n* 14.2.4 一个完整的例子 723\n* 14.2.5 缩写长格式选项 725\n* 14.2.6 GNU式选项解析 725\n* 14.2.7 结束参数处理 726\n* 14.3 readline：GNU readline库 727\n* 14.3.1 配置readline 727\n* 14.3.2 完成文本 728\n* 14.3.3 访问完成缓冲区 731\n* 14.3.4 输入历史 733\n* 14.3.5 hook 736\n* 14.4 getpass：安全密码提示 737\n* 14.4.1 示例 737\n* 14.4.2 无终端使用getpass 738\n* 14.5 cmd：面向行的命令处理器 739\n* 14.5.1 处理命令 739\n* 14.5.2 命令参数 740\n* 14.5.3 现场帮助 741\n* 14.5.4 自动完成 742\n* 14.5.5 覆盖基类方法 744\n* 14.5.6 通过属性配置Cmd 745\n* 14.5.7 运行shell命令 746\n* 14.5.8 候选输入 747\n* 14.5.9 sys.argv的命令 748\n* 14.6 shlex：解析shell类语法 749\n* 14.6.1 解析加引号的字符串 749\n* 14.6.2 为shell建立安全的字符串 751\n* 14.6.3 嵌入注释 751\n* 14.6.4 将字符串分解为token 752\n* 14.6.5 包含其他token源 752\n* 14.6.6 控制解析器 753\n* 14.6.7 错误处理 755\n* 14.6.8 POSIX与非POSIX解析 756\n* 14.7 configparser：处理配置文件 757\n* 14.7.1 配置文件格式 757\n* 14.7.2 读取配置文件 758\n* 14.7.3 访问配置设置 759\n* 14.7.4 修改设置 765\n* 14.7.5 保存配置文件 766\n* 14.7.6 选项搜索路径 767\n* 14.7.7 用拼接合并值 768\n* 14.8 logging：报告状态、错误和信息消息 772\n* 14.8.1 日志系统的组成 773\n* 14.8.2 应用与库中的日志记录 773\n* 14.8.3 记入文件 773\n* 14.8.4 旋转日志文件 774\n* 14.8.5 详细级别 774\n* 14.8.6 命名日志记录器实例 776\n* 14.8.7 日志树 776\n* 14.8.8 与warnings模块集成 777\n* 14.9 fileinput：命令行过滤器框架 778\n* 14.9.1 将m3u文件转换为RSS 778\n* 14.9.2 进度元数据 779\n* 14.9.3 原地过滤 781\n* 14.10 atexit：程序关闭回调 782\n* 14.10.1 注册退出回调 782\n* 14.10.2 修饰符语法 783\n* 14.10.3 撤销回调 784\n* 14.10.4 什么情况下不调用atexit函数 785\n* 14.10.5 处理异常 786\n* 14.11 sched：定时事件调度器 787\n* 14.11.1 有延迟地运行事件 788\n* 14.11.2 重叠事件 788\n* 14.11.3 事件优先级 789\n* 14.11.4 取消事件 790\n* 第 15 章 国际化和本地化 791\n* 15.1 gettext：消息编目 791\n* 15.1.1 转换工作流概述 791\n* 15.1.2 由源代码创建消息编目 792\n* 15.1.3 运行时查找消息编目 794\n* 15.1.4 复数值 795\n* 15.1.5 应用与模块本地化 797\n* 15.1.6 切换转换 798\n* 15.2 locale：文化本地化API 798\n* 15.2.1 探查当前本地化环境 799\n* 15.2.2 货币 803\n* 15.2.3 格式化数字 804\n* 15.2.4 解析数字 805\n* 15.2.5 日期和时间 806\n* 第 16 章 开发工具 807\n* 16.1 pydoc：模块的联机帮助 808\n* 16.1.1 纯文本帮助 808\n* 16.1.2 HTML帮助 809\n* 16.1.3 交互式帮助 809\n* 16.2 doctest：通过文档完成测试 810\n* 16.2.1 起步 810\n* 16.2.2 处理不可预测的输出 811\n* 16.2.3 traceback 814\n* 16.2.4 避开空白符 815\n* 16.2.5 测试位置 819\n* 16.2.6 外部文档 822\n* 16.2.7 运行测试 824\n* 16.2.8 测试上下文 827\n* 16.3 unittest：自动测试框架 829\n* 16.3.1 基本测试结构 829\n* 16.3.2 运行测试 829\n* 16.3.3 测试结果 830\n* 16.3.4 断言真值 831\n* 16.3.5 测试相等性 832\n* 16.3.6 几乎相等？ 833\n* 16.3.7 容器 833\n* 16.3.8 测试异常 837\n* 16.3.9 测试固件 838\n* 16.3.10 用不同输入重复测试 840\n* 16.3.11 跳过测试 842\n* 16.3.12 忽略失败测试 842\n* 16.4 trace：执行程序流 843\n* 16.4.1 示例程序 843\n* 16.4.2 跟踪执行 844\n* 16.4.3 代码覆盖 845\n* 16.4.4 调用关系 847\n* 16.4.5 编程接口 848\n* 16.4.6 保存结果数据 849\n* 16.4.7 选项 850\n* 16.5 traceback：异常和栈轨迹 850\n* 16.5.1 支持函数 851\n* 16.5.2 检查栈 851\n* 16.5.3 traceback异常 853\n* 16.5.4 底层异常API 854\n* 16.5.5 底层栈API 857\n* 16.6 cgitb：详细的traceback报告 859\n* 16.6.1 标准traceback转储 859\n* 16.6.2 启用详细的traceback 860\n* 16.6.3 traceback中的局部变量 862\n* 16.6.4 异常属性 864\n* 16.6.5 HTML输出 866\n* 16.6.6 记录traceback 866\n* 16.7 pdb：交互式调试工具 868\n* 16.7.1 启动调试工具 869\n* 16.7.2 控制调试工具 871\n* 16.7.3 断点 881\n* 16.7.4 改变执行流 890\n* 16.7.5 用别名定制调试工具 895\n* 16.7.6 保存配置设置 897\n* 16.8 profile和pstats：性能分析 898\n* 16.8.1 运行性能分析工具 898\n* 16.8.2 在上下文中运行 901\n* 16.8.3 pstats：保存和处理统计信息 901\n* 16.8.4 限制报告内容 903\n* 16.8.5 调用者/被调用者图 903\n* 16.9 timeit：测量小段Python代码执行的时间 905\n* 16.9.1 模块内容 905\n* 16.9.2 基本示例 905\n* 16.9.3 将值存储在字典中 906\n* 16.9.4 从命令行执行 908\n* 16.10 tabnanny：缩进验证工具 909\n* 16.11 compileall：字节编译源文件 910\n* 16.11.1 编译一个目录 910\n* 16.11.2 忽略文件 911\n* 16.11.3 编译sys.path 912\n* 16.11.4 编译单个文件 912\n* 16.11.5 从命令行运行 913\n* 16.12 pyclbr：类浏览器 914\n* 16.12.1 扫描类 915\n* 16.12.2 扫描函数 916\n* 16.13 venv：创建虚拟环境 917\n* 16.13.1 创建环境 917\n* 16.13.2 虚拟环境的内容 917\n* 16.13.3 使用虚拟环境 918\n* 16.14 ensurepip：安装Python包安装工具 920\n* 第 17 章 运行时特性 922\n* 17.1 site：全站点配置 922\n* 17.1.1 导入路径 922\n* 17.1.2 用户目录 923\n* 17.1.3 路径配置文件 924\n* 17.1.4 定制站点配置 926\n* 17.1.5 定制用户配置 927\n* 17.1.6 禁用site模块 929\n* 17.2 sys：系统特定配置 929\n* 17.2.1 解释器设置 929\n* 17.2.2 运行时环境 935\n* 17.2.3 内存管理和限制 937\n* 17.2.4 异常处理 942\n* 17.2.5 底层线程支持 944\n* 17.2.6 模块和导入 947\n* 17.2.7 跟踪程序运行情况 963\n* 17.3 os：可移植访问操作系统特定特性 968\n* 17.3.1 检查文件系统内容 968\n* 17.3.2 管理文件系统权限 971\n* 17.3.3 创建和删除目录 973\n* 17.3.4 处理符号链接 973\n* 17.3.5 安全地替换现有文件 974\n* 17.3.6 检测和改变进程所有者 975\n* 17.3.7 管理进程环境 976\n* 17.3.8 管理进程工作目录 977\n* 17.3.9 运行外部命令 977\n* 17.3.10 用os.fork()创建进程 979\n* 17.3.11 等待子进程 980\n* 17.3.12 Spawn创建新进程 982\n* 17.3.13 操作系统错误码 982\n* 17.4 platform：系统版本信息 983\n* 17.4.1 解释器 983\n* 17.4.2 平台 984\n* 17.4.3 操作系统和硬件信息 985\n* 17.4.4 可执行程序体系结构 986\n* 17.5 resource：系统资源管理 987\n* 17.5.1 当前使用情况 987\n* 17.5.2 资源限制 988\n* 17.6 gc：垃圾回收器 990\n* 17.6.1 跟踪引用 990\n* 17.6.2 强制垃圾回收 992\n* 17.6.3 查找无法回收的对象引用 993\n* 17.6.4 回收阈值和代 995\n* 17.6.5 调试 998\n* 17.7 sysconfig：解释器编译时配置 1002\n* 17.7.1 配置变量 1002\n* 17.7.2 安装路径 1004\n* 17.7.3 Python版本和平台 1007\n* 第 18 章 语言工具 1009\n* 18.1 warnings：非致命警告 1009\n* 18.1.1 分类和过滤 1010\n* 18.1.2 生成警告 1010\n* 18.1.3 用模式过滤 1011\n* 18.1.4 重复的警告 1013\n* 18.1.5 候选消息传送函数 1013\n* 18.1.6 格式化 1014\n* 18.1.7 警告中的栈层次 1014\n* 18.2 abc：抽象基类 1015\n* 18.2.1 ABC如何工作 1015\n* 18.2.2 注册一个具体类 1016\n* 18.2.3 通过派生实现 1017\n* 18.2.4 辅助基类 1017\n* 18.2.5 不完整的实现 1018\n* 18.2.6 ABC中的具体方法 1019\n* 18.2.7 抽象属性 1020\n* 18.2.8 抽象类和静态方法 1022\n* 18.3 dis：Python字节码反汇编工具 1023\n* 18.3.1 基本反汇编 1023\n* 18.3.2 反汇编函数 1024\n* 18.3.3 类 1025\n* 18.3.4 源代码 1026\n* 18.3.5 使用反汇编调试 1027\n* 18.3.6 循环的性能分析 1028\n* 18.3.7 编译器优化 1033\n* 18.4 inspect：检查现场对象 1035\n* 18.4.1 示例模块 1035\n* 18.4.2 检查模块 1035\n* 18.4.3 检查类 1036\n* 18.4.4 检查实例 1038\n* 18.4.5 文档串 1038\n* 18.4.6 获取源代码 1039\n* 18.4.7 方法和函数签名 1041\n* 18.4.8 类层次体系 1043\n* 18.4.9 方法解析顺序 1044\n* 18.4.10 栈与帧 1045\n* 18.4.11 命令行接口 1047\n* 第 19 章 模块和包 1048\n* 19.1 importlib：Python的导入机制 1048\n* 19.1.1 示例包 1048\n* 19.1.2 模块类型 1049\n* 19.1.3 导入模块 1049\n* 19.1.4 加载工具 1051\n* 19.2 pkgutil：包工具 1052\n* 19.2.1 包导入路径 1052\n* 19.2.2 包的开发版本 1054\n* 19.2.3 用PKG文件管理路径 1055\n* 19.2.4 嵌套包 1056\n* 19.2.5 包数据 1058\n* 19.3 zipimport：从ZIP归档加载Python代码 1060\n* 19.3.1 示例 1060\n* 19.3.2 查找模块 1061\n* 19.3.3 访问代码 1061\n* 19.3.4 源代码 1062\n* 19.3.5 包 1063\n* 19.3.6 数据 1063\n* 附录A 移植说明 1066\n* 附录B 标准库之外 1081\n\n\n\u003c/pre\u003e\n\u003c/details\u003e\n\n\n\n## English Version\n![](.assets/cover_en.jpg)\n\n\n\n## Table of Contents\n\n\u003cdetails\u003e\n\u003csummary\u003e展开查看\u003c/summary\u003e\n\u003cpre\u003e\n\n* Chapter 1 Text 1\n* 1.1 string: Text Constants and Templates 1\n* 1.1.1 Functions 1\n* 1.1.2 Templates 2\n* 1.1.3 Advanced Templates 4\n* 1.1.4 Formatter 6\n* 1.1.5 Constants 6\n* 1.2 textwrap: Formatting Text Paragraphs 7\n* 1.2.1 Example Data 8\n* 1.2.2 Filling Paragraphs 8\n* 1.2.3 Removing Existing Indentation 8\n* 1.2.4 Combining Dedent and Fill 9\n* 1.2.5 Indenting Blocks 10\n* 1.2.6 Hanging Indents 12\n* 1.2.7 Truncating Long Text 12\n* 1.3 re: Regular Expressions 13\n* 1.3.1 Finding Patterns in Text 14\n* 1.3.2 Compiling Expressions 15\n* 1.3.3 Multiple Matches 16\n* 1.3.4 Pattern Syntax 17\n* 1.3.5 Constraining the Search 28\n* 1.3.6 Dissecting Matches with Groups 30\n* 1.3.7 Search Options 36\n* 1.3.8 Looking Ahead or Behind 44\n* 1.3.9 Self-referencing Expressions 48\n* 1.3.10 Modifying Strings with Patterns 53\n* 1.3.11 Splitting with Patterns 55\n* 1.4 diﬄib: Compare Sequences 58\n* 1.4.1 Comparing Bodies of Text 58\n* 1.4.2 Junk Data 61\n* 1.4.3 Comparing Arbitrary Types 62\n* ixx Contents\n* Chapter 2 Data Structures 65\n* 2.1 enum: Enumeration Type 66\n* 2.1.1 Creating Enumerations 66\n* 2.1.2 Iteration 67\n* 2.1.3 Comparing Enums 67\n* 2.1.4 Unique Enumeration Values 69\n* 2.1.5 Creating Enumerations Programmatically 71\n* 2.1.6 Non-integer Member Values 72\n* 2.2 collections: Container Data Types 75\n* 2.2.1 ChainMap: Search Multiple Dictionaries 75\n* 2.2.2 Counter: Count Hashable Objects 79\n* 2.2.3 defaultdict: Missing Keys Return a Default Value 83\n* 2.2.4 deque: Double-Ended Queue 84\n* 2.2.5 namedtuple: Tuple Subclass with Named Fields 89\n* 2.2.6 OrderedDict: Remember the Order Keys Are Added to a Dictionary 94\n* 2.2.7 collections.abc: Abstract Base Classes for Containers 97\n* 2.3 array: Sequence of Fixed-Type Data 98\n* 2.3.1 Initialization 98\n* 2.3.2 Manipulating Arrays 99\n* 2.3.3 Arrays and Files 100\n* 2.3.4 Alternative Byte Ordering 101\n* 2.4 heapq: Heap Sort Algorithm 103\n* 2.4.1 Example Data 103\n* 2.4.2 Creating a Heap 104\n* 2.4.3 Accessing the Contents of a Heap 105\n* 2.4.4 Data Extremes from a Heap 107\n* 2.4.5 Eﬃciently Merging Sorted Sequences 108\n* 2.5 bisect: Maintain Lists in Sorted Order 109\n* 2.5.1 Inserting in Sorted Order 109\n* 2.5.2 Handling Duplicates 110\n* 2.6 queue: Thread-Safe FIFO Implementation 111\n* 2.6.1 Basic FIFO Queue 112\n* 2.6.2 LIFO Queue 112\n* 2.6.3 Priority Queue 113\n* 2.6.4 Building a Threaded Podcast Client 114\n* 2.7 struct: Binary Data Structures 117\n* 2.7.1 Functions Versus Struct Class 117\n* 2.7.2 Packing and Unpacking 117\n* 2.7.3 Endianness 118\n* 2.7.4 Buﬀers 120\n* 2.8 weakref: Impermanent References to Objects 121\n* 2.8.1 References 122\n* 2.8.2 Reference Callbacks 122\n* 2.8.3 Finalizing Objects 123\n* 2.8.4 Proxies 126\n* 2.8.5 Caching Objects 127Contents xi\n* 2.9 copy: Duplicate Objects 130\n* 2.9.1 Shallow Copies 130\n* 2.9.2 Deep Copies 131\n* 2.9.3 Customizing Copy Behavior 132\n* 2.9.4 Recursion in Deep Copy 133\n* 2.10 pprint: Pretty-Print Data Structures 136\n* 2.10.1 Printing 136\n* 2.10.2 Formatting 137\n* 2.10.3 Arbitrary Classes 138\n* 2.10.4 Recursion 139\n* 2.10.5 Limiting Nested Output 139\n* 2.10.6 Controlling Output Width 140\n* Chapter 3 Algorithms 143\n* 3.1 functools: Tools for Manipulating Functions 143\n* 3.1.1 Decorators 143\n* 3.1.2 Comparison 151\n* 3.1.3 Caching 155\n* 3.1.4 Reducing a Data Set 158\n* 3.1.5 Generic Functions 161\n* 3.2 itertools: Iterator Functions 163\n* 3.2.1 Merging and Splitting Iterators 164\n* 3.2.2 Converting Inputs 167\n* 3.2.3 Producing New Values 169\n* 3.2.4 Filtering 172\n* 3.2.5 Grouping Data 175\n* 3.2.6 Combining Inputs 176\n* 3.3 operator: Functional Interface to Built-in Operators 183\n* 3.3.1 Logical Operations 183\n* 3.3.2 Comparison Operators 184\n* 3.3.3 Arithmetic Operators 184\n* 3.3.4 Sequence Operators 186\n* 3.3.5 In-Place Operators 187\n* 3.3.6 Attribute and Item “Getters” 188\n* 3.3.7 Combining Operators and Custom Classes 190\n* 3.4 contextlib: Context Manager Utilities 191\n* 3.4.1 Context Manager API 191\n* 3.4.2 Context Managers as Function Decorators 194\n* 3.4.3 From Generator to Context Manager 196\n* 3.4.4 Closing Open Handles 198\n* 3.4.5 Ignoring Exceptions 199\n* 3.4.6 Redirecting Output Streams 201\n* 3.4.7 Dynamic Context Manager Stacks 202xii Contents\n* Chapter 4 Dates and Times 211\n* 4.1 time: Clock Time 211\n* 4.1.1 Comparing Clocks 211\n* 4.1.2 Wall Clock Time 213\n* 4.1.3 Monotonic Clocks 214\n* 4.1.4 Processor Clock Time 214\n* 4.1.5 Performance Counter 216\n* 4.1.6 Time Components 217\n* 4.1.7 Working with Time Zones 218\n* 4.1.8 Parsing and Formatting Times 219\n* 4.2 datetime: Date and Time Value Manipulation 221\n* 4.2.1 Times 221\n* 4.2.2 Dates 222\n* 4.2.3 timedeltas 225\n* 4.2.4 Date Arithmetic 226\n* 4.2.5 Comparing Values 228\n* 4.2.6 Combining Dates and Times 228\n* 4.2.7 Formatting and Parsing 230\n* 4.2.8 Time Zones 231\n* 4.3 calendar: Work with Dates 233\n* 4.3.1 Formatting Examples 233\n* 4.3.2 Locales 236\n* 4.3.3 Calculating Dates 236\n* Chapter 5 Mathematics 239\n* 5.1 decimal: Fixed- and Floating-Point Math 239\n* 5.1.1 Decimal 239\n* 5.1.2 Formatting 241\n* 5.1.3 Arithmetic 242\n* 5.1.4 Special Values 243\n* 5.1.5 Context 244\n* 5.2 fractions: Rational Numbers 250\n* 5.2.1 Creating Fraction Instances 250\n* 5.2.2 Arithmetic 252\n* 5.2.3 Approximating Values 253\n* 5.3 random: Pseudorandom Number Generators 254\n* 5.3.1 Generating Random Numbers 254\n* 5.3.2 Seeding 255\n* 5.3.3 Saving State 255\n* 5.3.4 Random Integers 257\n* 5.3.5 Picking Random Items 258\n* 5.3.6 Permutations 258\n* 5.3.7 Sampling 260\n* 5.3.8 Multiple Simultaneous Generators 261\n* 5.3.9 SystemRandom 262\n* 5.3.10 Non-uniform Distributions 263Contents xiii\n* 5.4 math: Mathematical Functions 264\n* 5.4.1 Special Constants 265\n* 5.4.2 Testing for Exceptional Values 265\n* 5.4.3 Comparing 267\n* 5.4.4 Converting Floating-Point Values to Integers 270\n* 5.4.5 Alternative Representations of Floating-Point Values 271\n* 5.4.6 Positive and Negative Signs 272\n* 5.4.7 Commonly Used Calculations 274\n* 5.4.8 Exponents and Logarithms 278\n* 5.4.9 Angles 282\n* 5.4.10 Trigonometry 284\n* 5.4.11 Hyperbolic Functions 288\n* 5.4.12 Special Functions 289\n* 5.5 statistics: Statistical Calculations 290\n* 5.5.1 Averages 290\n* 5.5.2 Variance 292\n* Chapter 6 The File System 295\n* 6.1 os.path: Platform-Independent Manipulation of Filenames 296\n* 6.1.1 Parsing Paths 296\n* 6.1.2 Building Paths 300\n* 6.1.3 Normalizing Paths 301\n* 6.1.4 File Times 302\n* 6.1.5 Testing Files 303\n* 6.2 pathlib: File System Paths as Objects 305\n* 6.2.1 Path Representations 305\n* 6.2.2 Building Paths 305\n* 6.2.3 Parsing Paths 307\n* 6.2.4 Creating Concrete Paths 309\n* 6.2.5 Directory Contents 309\n* 6.2.6 Reading and Writing Files 312\n* 6.2.7 Manipulating Directories and Symbolic Links 312\n* 6.2.8 File Types 313\n* 6.2.9 File Properties 315\n* 6.2.10 Permissions 317\n* 6.2.11 Deleting 318\n* 6.3 glob: Filename Pattern Matching 319\n* 6.3.1 Example Data 320\n* 6.3.2 Wildcards 320\n* 6.3.3 Single-Character Wildcard 321\n* 6.3.4 Character Ranges 322\n* 6.3.5 Escaping Meta-characters 322\n* 6.4 fnmatch: Unix-Style Glob Pattern Matching 323\n* 6.4.1 Simple Matching 323\n* 6.4.2 Filtering 325\n* 6.4.3 Translating Patterns 325xiv Contents\n* 6.5 linecache: Read Text Files Eﬃciently 326\n* 6.5.1 Test Data 326\n* 6.5.2 Reading Speciﬁc Lines 327\n* 6.5.3 Handling Blank Lines 328\n* 6.5.4 Error Handling 328\n* 6.5.5 Reading Python Source Files 329\n* 6.6 tempﬁle: Temporary File System Objects 330\n* 6.6.1 Temporary Files 331\n* 6.6.2 Named Files 333\n* 6.6.3 Spooled Files 333\n* 6.6.4 Temporary Directories 335\n* 6.6.5 Predicting Names 335\n* 6.6.6 Temporary File Location 336\n* 6.7 shutil: High-Level File Operations 337\n* 6.7.1 Copying Files 337\n* 6.7.2 Copying File Metadata 340\n* 6.7.3 Working with Directory Trees 342\n* 6.7.4 Finding Files 345\n* 6.7.5 Archives 346\n* 6.7.6 File System Space 350\n* 6.8 ﬁlecmp: Compare Files 351\n* 6.8.1 Example Data 351\n* 6.8.2 Comparing Files 353\n* 6.8.3 Comparing Directories 355\n* 6.8.4 Using Diﬀerences in a Program 357\n* 6.9 mmap: Memory-Map Files 361\n* 6.9.1 Reading 361\n* 6.9.2 Writing 362\n* 6.9.3 Regular Expressions 364\n* 6.10 codecs: String Encoding and Decoding 365\n* 6.10.1 Unicode Primer 365\n* 6.10.2 Working with Files 368\n* 6.10.3 Byte Order 370\n* 6.10.4 Error Handling 372\n* 6.10.5 Encoding Translation 376\n* 6.10.6 Non-Unicode Encodings 377\n* 6.10.7 Incremental Encoding 378\n* 6.10.8 Unicode Data and Network Communication 380\n* 6.10.9 Deﬁning a Custom Encoding 383\n* 6.11 io: Text, Binary, and Raw Stream I/O Tools 390\n* 6.11.1 In-Memory Streams 390\n* 6.11.2 Wrapping Byte Streams for Text Data 392Contents xv\n* Chapter 7 Data Persistence and Exchange 395\n* 7.1 pickle: Object Serialization 396\n* 7.1.1 Encoding and Decoding Data in Strings 396\n* 7.1.2 Working with Streams 397\n* 7.1.3 Problems Reconstructing Objects 399\n* 7.1.4 Unpicklable Objects 400\n* 7.1.5 Circular References 402\n* 7.2 shelve: Persistent Storage of Objects 405\n* 7.2.1 Creating a New Shelf 405\n* 7.2.2 Writeback 406\n* 7.2.3 Speciﬁc Shelf Types 408\n* 7.3 dbm: Unix Key–Value Databases 408\n* 7.3.1 Database Types 408\n* 7.3.2 Creating a New Database 409\n* 7.3.3 Opening an Existing Database 410\n* 7.3.4 Error Cases 411\n* 7.4 sqlite3: Embedded Relational Database 412\n* 7.4.1 Creating a Database 412\n* 7.4.2 Retrieving Data 415\n* 7.4.3 Query Metadata 417\n* 7.4.4 Row Objects 417\n* 7.4.5 Using Variables with Queries 419\n* 7.4.6 Bulk Loading 421\n* 7.4.7 Deﬁning New Column Types 422\n* 7.4.8 Determining Types for Columns 426\n* 7.4.9 Transactions 428\n* 7.4.10 Isolation Levels 431\n* 7.4.11 In-Memory Databases 434\n* 7.4.12 Exporting the Contents of a Database 435\n* 7.4.13 Using Python Functions in SQL 436\n* 7.4.14 Querying with Regular Expressions 439\n* 7.4.15 Custom Aggregation 440\n* 7.4.16 Threading and Connection Sharing 441\n* 7.4.17 Restricting Access to Data 442\n* 7.5 xml.etree.ElementTree: XML Manipulation API 445\n* 7.5.1 Parsing an XML Document 445\n* 7.5.2 Traversing the Parsed Tree 446\n* 7.5.3 Finding Nodes in a Document 447\n* 7.5.4 Parsed Node Attributes 449\n* 7.5.5 Watching Events While Parsing 451\n* 7.5.6 Creating a Custom Tree Builder 453\n* 7.5.7 Parsing Strings 455\n* 7.5.8 Building Documents With Element Nodes 457\n* 7.5.9 Pretty-Printing XML 458\n* 7.5.10 Setting Element Properties 459xvi Contents\n* 7.5.11 Building Trees from Lists of Nodes 461\n* 7.5.12 Serializing XML to a Stream 464\n* 7.6 csv: Comma-Separated Value Files 466\n* 7.6.1 Reading 466\n* 7.6.2 Writing 467\n* 7.6.3 Dialects 469\n* 7.6.4 Using Field Names 474\n* Chapter 8 Data Compression and Archiving 477\n* 8.1 zlib: GNU zlib Compression 477\n* 8.1.1 Working with Data in Memory 477\n* 8.1.2 Incremental Compression and Decompression 479\n* 8.1.3 Mixed Content Streams 480\n* 8.1.4 Checksums 481\n* 8.1.5 Compressing Network Data 482\n* 8.2 gzip: Read and Write GNU zip Files 486\n* 8.2.1 Writing Compressed Files 486\n* 8.2.2 Reading Compressed Data 489\n* 8.2.3 Working with Streams 490\n* 8.3 bz2: bzip2 Compression 491\n* 8.3.1 One-Shot Operations in Memory 492\n* 8.3.2 Incremental Compression and Decompression 493\n* 8.3.3 Mixed-Content Streams 494\n* 8.3.4 Writing Compressed Files 495\n* 8.3.5 Reading Compressed Files 497\n* 8.3.6 Reading and Writing Unicode Data 498\n* 8.3.7 Compressing Network Data 499\n* 8.4 tarﬁle: Tar Archive Access 503\n* 8.4.1 Testing Tar Files 503\n* 8.4.2 Reading Metadata from an Archive 504\n* 8.4.3 Extracting Files from an Archive 506\n* 8.4.4 Creating New Archives 508\n* 8.4.5 Using Alternative Archive Member Names 508\n* 8.4.6 Writing Data from Sources Other Than Files 509\n* 8.4.7 Appending to Archives 510\n* 8.4.8 Working with Compressed Archives 510\n* 8.5 zipﬁle: ZIP Archive Access 511\n* 8.5.1 Testing ZIP Files 512\n* 8.5.2 Reading Metadata from an Archive 512\n* 8.5.3 Extracting Archived Files From an Archive 514\n* 8.5.4 Creating New Archives 514\n* 8.5.5 Using Alternative Archive Member Names 516\n* 8.5.6 Writing Data from Sources Other Than Files 517\n* 8.5.7 Writing with a ZipInfo Instance 517\n* 8.5.8 Appending to Files 518Contents xvii\n* 8.5.9 Python ZIP Archives 519\n* 8.5.10 Limitations 521\n* Chapter 9 Cryptography 523\n* 9.1 hashlib: Cryptographic Hashing 523\n* 9.1.1 Hash Algorithms 523\n* 9.1.2 Sample Data 524\n* 9.1.3 MD5 Example 524\n* 9.1.4 SHA1 Example 525\n* 9.1.5 Creating a Hash by Name 525\n* 9.1.6 Incremental Updates 526\n* 9.2 hmac: Cryptographic Message Signing and Veriﬁcation 528\n* 9.2.1 Signing Messages 528\n* 9.2.2 Alternative Digest Types 528\n* 9.2.3 Binary Digests 529\n* 9.2.4 Applications of Message Signatures 530\n* Chapter 10 Concurrency with Processes, Threads, and Coroutines 535\n* 10.1 subprocess: Spawning Additional Processes 535\n* 10.1.1 Running External Command 536\n* 10.1.2 Working with Pipes Directly 542\n* 10.1.3 Connecting Segments of a Pipe 545\n* 10.1.4 Interacting with Another Command 546\n* 10.1.5 Signaling Between Processes 548\n* 10.2 signal: Asynchronous System Events 553\n* 10.2.1 Receiving Signals 554\n* 10.2.2 Retrieving Registered Handlers 555\n* 10.2.3 Sending Signals 556\n* 10.2.4 Alarms 556\n* 10.2.5 Ignoring Signals 557\n* 10.2.6 Signals and Threads 558\n* 10.3 threading: Manage Concurrent Operations Within a Process 560\n* 10.3.1 Thread Objects 560\n* 10.3.2 Determining the Current Thread 562\n* 10.3.3 Daemon Versus Non-daemon Threads 564\n* 10.3.4 Enumerating All Threads 567\n* 10.3.5 Subclassing Thread 568\n* 10.3.6 Timer Threads 570\n* 10.3.7 Signaling Between Threads 571\n* 10.3.8 Controlling Access to Resources 572\n* 10.3.9 Synchronizing Threads 578\n* 10.3.10 Limiting Concurrent Access to Resources 581\n* 10.3.11 Thread Speciﬁc Data 583\n* 10.4 multiprocessing: Manage Processes Like Threads 586\n* 10.4.1 multiprocessing Basics 586\n* 10.4.2 Importable Target Functions 587xviii Contents\n* 10.4.3 Determining the Current Process 588\n* 10.4.4 Daemon Processes 589\n* 10.4.5 Waiting for Processes 591\n* 10.4.6 Terminating Processes 593\n* 10.4.7 Process Exit Status 594\n* 10.4.8 Logging 596\n* 10.4.9 Subclassing Process 597\n* 10.4.10 Passing Messages to Processes 598\n* 10.4.11 Signaling Between Processes 602\n* 10.4.12 Controlling Access to Resources 603\n* 10.4.13 Synchronizing Operations 604\n* 10.4.14 Controlling Concurrent Access to Resources 605\n* 10.4.15 Managing Shared State 608\n* 10.4.16 Shared Namespaces 608\n* 10.4.17 Process Pools 611\n* 10.4.18 Implementing MapReduce 613\n* 10.5 asyncio: Asynchronous I/O, Event Loop, and Concurrency Tools 617\n* 10.5.1 Asynchronous Concurrency Concepts 618\n* 10.5.2 Cooperative Multitasking with Coroutines 618\n* 10.5.3 Scheduling Calls to Regular Functions 622\n* 10.5.4 Producing Results Asynchronously 625\n* 10.5.5 Executing Tasks Concurrently 628\n* 10.5.6 Composing Coroutines with Control Structures 632\n* 10.5.7 Synchronization Primitives 637\n* 10.5.8 Asynchronous I/O with Protocol Class Abstractions 644\n* 10.5.9 Asynchronous I/O Using Coroutines and Streams 650\n* 10.5.10 Using SSL 656\n* 10.5.11 Interacting with Domain Name Services 658\n* 10.5.12 Working with Subprocesses 661\n* 10.5.13 Receiving Unix Signals 668\n* 10.5.14 Combining Coroutines with Threads and Processes 670\n* 10.5.15 Debugging with asyncio 673\n* 10.6 concurrent.futures: Manage Pools of Concurrent Tasks 677\n* 10.6.1 Using map() with a Basic Thread Pool 677\n* 10.6.2 Scheduling Individual Tasks 678\n* 10.6.3 Waiting for Tasks in Any Order 679\n* 10.6.4 Future Callbacks 680\n* 10.6.5 Canceling Tasks 681\n* 10.6.6 Exceptions in Tasks 683\n* 10.6.7 Context Manager 683\n* 10.6.8 Process Pools 684Contents xix\n* Chapter 11 Networking 687\n* 11.1 ipaddress: Internet Addresses 687\n* 11.1.1 Addresses 687\n* 11.1.2 Networks 688\n* 11.1.3 Interfaces 692\n* 11.2 socket: Network Communication 693\n* 11.2.1 Addressing, Protocol Families, and Socket Types 693\n* 11.2.2 TCP/IP Client and Server 704\n* 11.2.3 User Datagram Client and Server 711\n* 11.2.4 Unix Domain Sockets 714\n* 11.2.5 Multicast 717\n* 11.2.6 Sending Binary Data 721\n* 11.2.7 Non-blocking Communication and Timeouts 723\n* 11.3 selectors: I/O Multiplexing Abstractions 724\n* 11.3.1 Operating Model 724\n* 11.3.2 Echo Server 724\n* 11.3.3 Echo Client 726\n* 11.3.4 Server and Client Together 727\n* 11.4 select: Wait for I/O Eﬃciently 728\n* 11.4.1 Using select() 729\n* 11.4.2 Non-blocking I/O with Timeouts 734\n* 11.4.3 Using poll() 737\n* 11.4.4 Platform-Speciﬁc Options 742\n* 11.5 socketserver: Creating Network Servers 742\n* 11.5.1 Server Types 742\n* 11.5.2 Server Objects 743\n* 11.5.3 Implementing a Server 743\n* 11.5.4 Request Handlers 743\n* 11.5.5 Echo Example 744\n* 11.5.6 Threading and Forking 749\n* Chapter 12 The Internet 753\n* 12.1 urllib.parse: Split URLs into Components 753\n* 12.1.1 Parsing 754\n* 12.1.2 Unparsing 756\n* 12.1.3 Joining 758\n* 12.1.4 Encoding Query Arguments 759\n* 12.2 urllib.request: Network Resource Access 761\n* 12.2.1 HTTP GET 761\n* 12.2.2 Encoding Arguments 763\n* 12.2.3 HTTP POST 764\n* 12.2.4 Adding Outgoing Headers 765\n* 12.2.5 Posting Form Data from a Request 766\n* 12.2.6 Uploading Files 767\n* 12.2.7 Creating Custom Protocol Handlers 770xx Contents\n* 12.3 urllib.robotparser: Internet Spider Access Control 773\n* 12.3.1 robots.txt 773\n* 12.3.2 Testing Access Permissions 774\n* 12.3.3 Long-Lived Spiders 775\n* 12.4 base64: Encode Binary Data with ASCII 776\n* 12.4.1 Base 64 Encoding 777\n* 12.4.2 Base64 Decoding 778\n* 12.4.3 URL-Safe Variations 778\n* 12.4.4 Other Encodings 779\n* 12.5 http.server: Base Classes for Implementing Web Servers 781\n* 12.5.1 HTTP GET 781\n* 12.5.2 HTTP POST 784\n* 12.5.3 Threading and Forking 786\n* 12.5.4 Handling Errors 787\n* 12.5.5 Setting Headers 788\n* 12.5.6 Command-Line Use 789\n* 12.6 http.cookies: HTTP Cookies 790\n* 12.6.1 Creating and Setting a Cookie 790\n* 12.6.2 Morsels 791\n* 12.6.3 Encoded Values 793\n* 12.6.4 Receiving and Parsing Cookie Headers 794\n* 12.6.5 Alternative Output Formats 795\n* 12.7 webbrowser: Displays Web Pages 796\n* 12.7.1 Simple Example 796\n* 12.7.2 Windows Versus Tabs 796\n* 12.7.3 Using a Speciﬁc Browser 796\n* 12.7.4 BROWSER Variable 797\n* 12.7.5 Command-Line Interface 797\n* 12.8 uuid: Universally Unique Identiﬁers 797\n* 12.8.1 UUID 1: IEEE 802 MAC Address 798\n* 12.8.2 UUID 3 and 5: Name-Based Values 800\n* 12.8.3 UUID 4: Random Values 802\n* 12.8.4 Working with UUID Objects 802\n* 12.9 json: JavaScript Object Notation 803\n* 12.9.1 Encoding and Decoding Simple Data Types 804\n* 12.9.2 Human-Consumable Versus Compact Output 805\n* 12.9.3 Encoding Dictionaries 807\n* 12.9.4 Working with Custom Types 807\n* 12.9.5 Encoder and Decoder Classes 810\n* 12.9.6 Working with Streams and Files 813\n* 12.9.7 Mixed Data Streams 813\n* 12.9.8 JSON at the Command Line 815\n* 12.10 xmlrpc.client: Client Library for XML-RPC 816\n* 12.10.1 Connecting to a Server 817\n* 12.10.2 Data Types 819Contents xxi\n* 12.10.3 Passing Objects 822\n* 12.10.4 Binary Data 823\n* 12.10.5 Exception Handling 825\n* 12.10.6 Combining Calls into One Message 826\n* 12.11 xmlrpc.server: An XML-RPC Server 827\n* 12.11.1 A Simple Server 828\n* 12.11.2 Alternate API Names 829\n* 12.11.3 Dotted API Names 830\n* 12.11.4 Arbitrary API Names 831\n* 12.11.5 Exposing Methods of Objects 832\n* 12.11.6 Dispatching Calls 834\n* 12.11.7 Introspection API 837\n* Chapter 13 Email 841\n* 13.1 smtplib: Simple Mail Transfer Protocol Client 841\n* 13.1.1 Sending an Email Message 841\n* 13.1.2 Authentication and Encryption 843\n* 13.1.3 Verifying an Email Address 846\n* 13.2 smtpd: Sample Mail Servers 847\n* 13.2.1 Mail Server Base Class 847\n* 13.2.2 Debugging Server 850\n* 13.2.3 Proxy Server 851\n* 13.3 mailbox: Manipulate Email Archives 852\n* 13.3.1 mbox 852\n* 13.3.2 Maildir 855\n* 13.3.3 Message Flags 862\n* 13.3.4 Other Formats 864\n* 13.4 imaplib: IMAP4 Client Library 864\n* 13.4.1 Variations 864\n* 13.4.2 Connecting to a Server 864\n* 13.4.3 Example Conﬁguration 866\n* 13.4.4 Listing Mailboxes 866\n* 13.4.5 Mailbox Status 869\n* 13.4.6 Selecting a Mailbox 871\n* 13.4.7 Searching for Messages 872\n* 13.4.8 Search Criteria 872\n* 13.4.9 Fetching Messages 874\n* 13.4.10 Whole Messages 880\n* 13.4.11 Uploading Messages 881\n* 13.4.12 Moving and Copying Messages 883\n* 13.4.13 Deleting Messages 884xxii Contents\n* Chapter 14 Application Building Blocks 887\n* 14.1 argparse: Command-Line Option and Argument Parsing 888\n* 14.1.1 Setting Up a Parser 888\n* 14.1.2 Deﬁning Arguments 888\n* 14.1.3 Parsing a Command Line 889\n* 14.1.4 Simple Examples 889\n* 14.1.5 Help Output 897\n* 14.1.6 Parser Organization 901\n* 14.1.7 Advanced Argument Processing 908\n* 14.2 getopt: Command-Line Option Parsing 916\n* 14.2.1 Function Arguments 916\n* 14.2.2 Short-Form Options 917\n* 14.2.3 Long-Form Options 917\n* 14.2.4 A Complete Example 918\n* 14.2.5 Abbreviating Long-Form Options 920\n* 14.2.6 GNU-Style Option Parsing 920\n* 14.2.7 Ending Argument Processing 922\n* 14.3 readline: The GNU readline Library 922\n* 14.3.1 Conﬁguring readline 923\n* 14.3.2 Completing Text 924\n* 14.3.3 Accessing the Completion Buﬀer 927\n* 14.3.4 Input History 931\n* 14.3.5 Hooks 934\n* 14.4 getpass: Secure Password Prompt 935\n* 14.4.1 Example 935\n* 14.4.2 Using getpass Without a Terminal 937\n* 14.5 cmd: Line-Oriented Command Processors 938\n* 14.5.1 Processing Commands 938\n* 14.5.2 Command Arguments 940\n* 14.5.3 Live Help 941\n* 14.5.4 Auto-Completion 942\n* 14.5.5 Overriding Base Class Methods 944\n* 14.5.6 Conﬁguring Cmd Through Attributes 946\n* 14.5.7 Running Shell Commands 947\n* 14.5.8 Alternative Inputs 948\n* 14.5.9 Commands from sys.argv 950\n* 14.6 shlex: Parse Shell-Style Syntaxes 951\n* 14.6.1 Parsing Quoted Strings 951\n* 14.6.2 Making Safe Strings for Shells 953\n* 14.6.3 Embedded Comments 954\n* 14.6.4 Splitting Strings into Tokens 954\n* 14.6.5 Including Other Sources of Tokens 955\n* 14.6.6 Controlling the Parser 956\n* 14.6.7 Error Handling 957\n* 14.6.8 POSIX Versus Non-POSIX Parsing 959Contents xxiii\n* 14.7 conﬁgparser: Work with Conﬁguration Files 960\n* 14.7.1 Conﬁguration File Format 961\n* 14.7.2 Reading Conﬁguration Files 961\n* 14.7.3 Accessing Conﬁguration Settings 963\n* 14.7.4 Modifying Settings 970\n* 14.7.5 Saving Conﬁguration Files 972\n* 14.7.6 Option Search Path 972\n* 14.7.7 Combining Values with Interpolation 975\n* 14.8 logging: Report Status, Error, and Informational Messages 980\n* 14.8.1 Logging Components 980\n* 14.8.2 Logging in Applications Versus Libraries 980\n* 14.8.3 Logging to a File 981\n* 14.8.4 Rotating Log Files 981\n* 14.8.5 Verbosity Levels 982\n* 14.8.6 Naming Logger Instances 984\n* 14.8.7 The Logging Tree 984\n* 14.8.8 Integration with the warnings Module 985\n* 14.9 ﬁleinput: Command-Line Filter Framework 986\n* 14.9.1 Converting M3U Files to RSS 987\n* 14.9.2 Progress Metadata 989\n* 14.9.3 In-Place Filtering 990\n* 14.10 atexit: Program Shutdown Callbacks 993\n* 14.10.1 Registering Exit Callbacks 993\n* 14.10.2 Decorator Syntax 994\n* 14.10.3 Canceling Callbacks 994\n* 14.10.4 When Are atexit Callbacks Not Called? 995\n* 14.10.5 Handling Exceptions 997\n* 14.11 sched: Timed Event Scheduler 998\n* 14.11.1 Running Events with a Delay 999\n* 14.11.2 Overlapping Events 1000\n* 14.11.3 Event Priorities 1001\n* 14.11.4 Canceling Events 1001\n* Chapter 15 Internationalization and Localization 1003\n* 15.1 gettext: Message Catalogs 1003\n* 15.1.1 Translation Workﬂow Overview 1003\n* 15.1.2 Creating Message Catalogs from Source Code 1004\n* 15.1.3 Finding Message Catalogs at Runtime 1007\n* 15.1.4 Plural Values 1008\n* 15.1.5 Application Versus Module Localization 1011\n* 15.1.6 Switching Translations 1012\n* 15.2 locale: Cultural Localization API 1012\n* 15.2.1 Probing the Current Locale 1013\n* 15.2.2 Currency 1018\n* 15.2.3 Formatting Numbers 1019xxiv Contents\n* 15.2.4 Parsing Numbers 1021\n* 15.2.5 Dates and Times 1022\n* Chapter 16 Developer Tools 1023\n* 16.1 pydoc: Online Help for Modules 1024\n* 16.1.1 Plain Text Help 1024\n* 16.1.2 HTML Help 1025\n* 16.1.3 Interactive Help 1026\n* 16.2 doctest: Testing Through Documentation 1026\n* 16.2.1 Getting Started 1026\n* 16.2.2 Handling Unpredictable Output 1028\n* 16.2.3 Tracebacks 1032\n* 16.2.4 Working Around Whitespace 1034\n* 16.2.5 Test Locations 1039\n* 16.2.6 External Documentation 1042\n* 16.2.7 Running Tests 1044\n* 16.2.8 Test Context 1048\n* 16.3 unittest: Automated Testing Framework 1051\n* 16.3.1 Basic Test Structure 1051\n* 16.3.2 Running Tests 1051\n* 16.3.3 Test Outcomes 1052\n* 16.3.4 Asserting Truth 1054\n* 16.3.5 Testing Equality 1054\n* 16.3.6 Almost Equal? 1055\n* 16.3.7 Containers 1056\n* 16.3.8 Testing for Exceptions 1061\n* 16.3.9 Test Fixtures 1062\n* 16.3.10 Repeating Tests with Diﬀerent Inputs 1065\n* 16.3.11 Skipping Tests 1066\n* 16.3.12 Ignoring Failing Tests 1068\n* 16.4 trace: Follow Program Flow 1069\n* 16.4.1 Example Program 1069\n* 16.4.2 Tracing Execution 1069\n* 16.4.3 Code Coverage 1070\n* 16.4.4 Calling Relationships 1073\n* 16.4.5 Programming Interface 1074\n* 16.4.6 Saving Result Data 1076\n* 16.4.7 Options 1077\n* 16.5 traceback: Exceptions and Stack Traces 1078\n* 16.5.1 Supporting Functions 1079\n* 16.5.2 Examining the Stack 1079\n* 16.5.3 TracebackException 1081\n* 16.5.4 Low-Level Exception APIs 1082\n* 16.5.5 Low-Level Stack APIs 1086Contents xxv\n* 16.6 cgitb: Detailed Traceback Reports 1089\n* 16.6.1 Standard Traceback Dumps 1089\n* 16.6.2 Enabling Detailed Tracebacks 1090\n* 16.6.3 Local Variables in Tracebacks 1093\n* 16.6.4 Exception Properties 1096\n* 16.6.5 HTML Output 1098\n* 16.6.6 Logging Tracebacks 1098\n* 16.7 pdb: Interactive Debugger 1101\n* 16.7.1 Starting the Debugger 1101\n* 16.7.2 Controlling the Debugger 1104\n* 16.7.3 Breakpoints 1117\n* 16.7.4 Changing Execution Flow 1129\n* 16.7.5 Customizing the Debugger with Aliases 1136\n* 16.7.6 Saving Conﬁguration Settings 1137\n* 16.8 proﬁle and pstats: Performance Analysis 1140\n* 16.8.1 Running the Proﬁler 1140\n* 16.8.2 Running in a Context 1143\n* 16.8.3 pstats: Saving and Working with Statistics 1144\n* 16.8.4 Limiting Report Contents 1145\n* 16.8.5 Caller/Callee Graphs 1146\n* 16.9 timeit: Time the Execution of Small Bits of Python Code 1148\n* 16.9.1 Module Contents 1148\n* 16.9.2 Basic Example 1148\n* 16.9.3 Storing Values in a Dictionary 1149\n* 16.9.4 From the Command Line 1152\n* 16.10 tabnanny: Indentation Validator 1153\n* 16.10.1 Running from the Command Line 1153\n* 16.11 compileall: Byte-Compile Source Files 1155\n* 16.11.1 Compiling One Directory 1155\n* 16.11.2 Ignoring Files 1156\n* 16.11.3 Compiling sys.path 1157\n* 16.11.4 Compiling Individual Files 1157\n* 16.11.5 From the Command Line 1158\n* 16.12 pyclbr: Class Browser 1160\n* 16.12.1 Scanning for Classes 1161\n* 16.12.2 Scanning for Functions 1162\n* 16.13 venv: Create Virtual Environments 1163\n* 16.13.1 Creating Environments 1163\n* 16.13.2 Contents of a Virtual Environment 1164\n* 16.13.3 Using Virtual Environments 1165\n* 16.14 ensurepip: Install the Python Package Installer 1167\n* 16.14.1 Installing pip 1167xxvi Contents\n* Chapter 17 Runtime Features 1169\n* 17.1 site: Site-wide Conﬁguration 1169\n* 17.1.1 Import Path 1169\n* 17.1.2 User Directories 1171\n* 17.1.3 Path Conﬁguration Files 1172\n* 17.1.4 Customizing Site Conﬁguration 1175\n* 17.1.5 Customizing User Conﬁguration 1176\n* 17.1.6 Disabling the site Module 1177\n* 17.2 sys: System-Speciﬁc Conﬁguration 1178\n* 17.2.1 Interpreter Settings 1178\n* 17.2.2 Runtime Environment 1185\n* 17.2.3 Memory Management and Limits 1187\n* 17.2.4 Exception Handling 1194\n* 17.2.5 Low-Level Thread Support 1197\n* 17.2.6 Modules and Imports 1200\n* 17.2.7 Tracing a Program As It Runs 1221\n* 17.3 os: Portable Access to Operating System–Speciﬁc Features 1227\n* 17.3.1 Examining the File System Contents 1228\n* 17.3.2 Managing File System Permissions 1230\n* 17.3.3 Creating and Deleting Directories 1233\n* 17.3.4 Working with Symbolic Links 1234\n* 17.3.5 Safely Replacing an Existing File 1234\n* 17.3.6 Detecting and Changing the Process Owner 1235\n* 17.3.7 Managing the Process Environment 1237\n* 17.3.8 Managing the Process Working Directory 1238\n* 17.3.9 Running External Commands 1239\n* 17.3.10 Creating Processes with os.fork() 1240\n* 17.3.11 Waiting for Child Processes 1242\n* 17.3.12 Spawning New Processes 1244\n* 17.3.13 Operating System Error Codes 1245\n* 17.4 platform: System Version Information 1246\n* 17.4.1 Interpreter 1246\n* 17.4.2 Platform 1247\n* 17.4.3 Operating System and Hardware Information 1248\n* 17.4.4 Executable Architecture 1250\n* 17.5 resource: System Resource Management 1251\n* 17.5.1 Current Usage 1251\n* 17.5.2 Resource Limits 1252\n* 17.6 gc: Garbage Collector 1254\n* 17.6.1 Tracing References 1255\n* 17.6.2 Forcing Garbage Collection 1258\n* 17.6.3 Finding References to Objects That Cannot Be Collected 1259\n* 17.6.4 Collection Thresholds and Generations 1261\n* 17.6.5 Debugging 1265Contents xxvii\n* 17.7 sysconﬁg: Interpreter Compile-Time Conﬁguration 1270\n* 17.7.1 Conﬁguration Variables 1270\n* 17.7.2 Installation Paths 1272\n* 17.7.3 Python Version and Platform 1276\n* Chapter 18 Language Tools 1279\n* 18.1 warnings: Non-fatal Alerts 1279\n* 18.1.1 Categories and Filtering 1280\n* 18.1.2 Generating Warnings 1280\n* 18.1.3 Filtering with Patterns 1281\n* 18.1.4 Repeated Warnings 1283\n* 18.1.5 Alternative Message Delivery Functions 1284\n* 18.1.6 Formatting 1285\n* 18.1.7 Stack Level in Warnings 1286\n* 18.2 abc: Abstract Base Classes 1287\n* 18.2.1 How ABCs Work 1287\n* 18.2.2 Registering a Concrete Class 1287\n* 18.2.3 Implementation Through Subclassing 1288\n* 18.2.4 Helper Base Class 1289\n* 18.2.5 Incomplete Implementations 1290\n* 18.2.6 Concrete Methods in ABCs 1291\n* 18.2.7 Abstract Properties 1292\n* 18.2.8 Abstract Class and Static Methods 1295\n* 18.3 dis: Python Byte-Code Disassembler 1296\n* 18.3.1 Basic Disassembly 1297\n* 18.3.2 Disassembling Functions 1297\n* 18.3.3 Classes 1300\n* 18.3.4 Source Code 1301\n* 18.3.5 Using Disassembly to Debug 1302\n* 18.3.6 Performance Analysis of Loops 1303\n* 18.3.7 Compiler Optimizations 1309\n* 18.4 inspect: Inspect Live Objects 1311\n* 18.4.1 Example Module 1311\n* 18.4.2 Inspecting Modules 1312\n* 18.4.3 Inspecting Classes 1314\n* 18.4.4 Inspecting Instances 1316\n* 18.4.5 Documentation Strings 1316\n* 18.4.6 Retrieving Source 1318\n* 18.4.7 Method and Function Signatures 1319\n* 18.4.8 Class Hierarchies 1322\n* 18.4.9 Method Resolution Order 1323\n* 18.4.10 The Stack and Frames 1324\n* 18.4.11 Command-Line Interface 1327xxviii Contents\n* Chapter 19 Modules and Packages 1329\n* 19.1 importlib: Python’s Import Mechanism 1329\n* 19.1.1 Example Package 1329\n* 19.1.2 Module Types 1330\n* 19.1.3 Importing Modules 1331\n* 19.1.4 Loaders 1332\n* 19.2 pkgutil: Package Utilities 1334\n* 19.2.1 Package Import Paths 1334\n* 19.2.2 Development Versions of Packages 1336\n* 19.2.3 Managing Paths with PKG Files 1338\n* 19.2.4 Nested Packages 1340\n* 19.2.5 Package Data 1341\n* 19.3 zipimport: Load Python Code from ZIP Archives 1344\n* 19.3.1 Example 1344\n* 19.3.2 Finding a Module 1345\n* 19.3.3 Accessing Code 1345\n* 19.3.4 Source 1346\n* 19.3.5 Packages 1348\n* 19.3.6 Data 1348\n* Appendix A Porting Notes 1351\n* A.1 References 1351\n* A.2 New Modules 1352\n* A.3 Renamed Modules 1352\n* A.4 Removed Modules 1354\n* A.4.1 bsddb 1354\n* A.4.2 commands 1354\n* A.4.3 compiler 1354\n* A.4.4 dircache 1354\n* A.4.5 EasyDialogs 1354\n* A.4.6 exceptions 1354\n* A.4.7 htmllib 1354\n* A.4.8 md5 1354\n* A.4.9 mimetools, MimeWriter, mimify, multiﬁle, and rfc822 1354\n* A.4.10 popen2 1354\n* A.4.11 posixﬁle 1355\n* A.4.12 sets 1355\n* A.4.13 sha 1355\n* A.4.14 sre 1355\n* A.4.15 statvfs 1355\n* A.4.16 thread 1355\n* A.4.17 user 1355\n* A.5 Deprecated Modules 1355\n* A.5.1 asyncore and asynchat 1355\n* A.5.2 formatter 1355Contents xxix\n* A.5.3 imp 1356\n* A.5.4 optparse 1356\n* A.6 Summary of Changes to Modules 1356\n* A.6.1 abc 1356\n* A.6.2 anydbm 1356\n* A.6.3 argparse 1356\n* A.6.4 array 1357\n* A.6.5 atexit 1357\n* A.6.6 base64 1357\n* A.6.7 bz2 1357\n* A.6.8 collections 1357\n* A.6.9 comands 1357\n* A.6.10 conﬁgparser 1358\n* A.6.11 contextlib 1358\n* A.6.12 csv 1358\n* A.6.13 datetime 1358\n* A.6.14 decimal 1358\n* A.6.15 fractions 1358\n* A.6.16 gc 1358\n* A.6.17 gettext 1359\n* A.6.18 glob 1359\n* A.6.19 http.cookies 1359\n* A.6.20 imaplib 1359\n* A.6.21 inspect 1359\n* A.6.22 itertools 1359\n* A.6.23 json 1359\n* A.6.24 locale 1359\n* A.6.25 logging 1360\n* A.6.26 mailbox 1360\n* A.6.27 mmap 1360\n* A.6.28 operator 1360\n* A.6.29 os 1360\n* A.6.30 os.path 1361\n* A.6.31 pdb 1361\n* A.6.32 pickle 1361\n* A.6.33 pipes 1362\n* A.6.34 platform 1362\n* A.6.35 random 1362\n* A.6.36 re 1362\n* A.6.37 shelve 1362\n* A.6.38 signal 1362\n* A.6.39 socket 1362\n* A.6.40 socketserver 1363\n* A.6.41 string 1363\n* A.6.42 struct 1363xxx Contents\n* A.6.43 subprocess 1363\n* A.6.44 sys 1363\n* A.6.45 threading 1364\n* A.6.46 time 1364\n* A.6.47 unittest 1364\n* A.6.48 UserDict, UserList, and UserString 1365\n* A.6.49 uuid 1365\n* A.6.50 whichdb 1365\n* A.6.51 xml.etree.ElementTree 1365\n* A.6.52 zipimport 1365\n* Appendix B Outside of the Standard Library 1367\n* B.1 Text 1367\n* B.2 Algorithms 1367\n* B.3 Dates and Times 1368\n* B.4 Mathematics 1368\n* B.5 Data Persistence and Exchange 1368\n* B.6 Cryptography 1369\n* B.7 Concurrency with Processes, Threads, and Coroutines 1369\n* B.8 The Internet 1369\n* B.9 Email 1370\n* B.10 Application Building Blocks 1370\n* B.11 Developer Tools 1371\n\n\n\u003c/pre\u003e\n\u003c/details\u003e\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbat67%2Fthe-python-standard-library-by-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbat67%2Fthe-python-standard-library-by-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbat67%2Fthe-python-standard-library-by-example/lists"}