没有合适的资源?快使用搜索试试~ 我知道了~
python第三方库文档


试读
953页
需积分: 0 53 下载量 73 浏览量
更新于2018-06-02
3
收藏 2.63MB PDF 举报
根据给定文件内容,我们可以提炼出Python编程中使用的第三方库及其相关知识点。以下是从文档中提取的关键知识点:
1. 数据持久化和交换
- 序列化对象:可以将对象状态转换为可存储的格式(如JSON或Pickle),以实现数据的持久化保存。
- 存储序列化对象:介绍了如何将序列化后的对象存储到文件或数据库中,便于数据交换。
- 关系型数据库:涉及如何使用Python进行关系型数据库(如SQLite, MySQL, PostgreSQL)的数据存取操作。
- 通过标准格式交换数据:介绍了数据通过XML, CSV, JSON等标准格式的交换方法。
2. 内存数据结构
- array:用于处理具有固定类型数据序列的模块。
- 排序:涉及排序算法和排序相关的数据结构。
- Queue:提供先进先出(FIFO)的数据结构,可用于线程安全的队列管理。
- collections:包含各种容器数据类型,如defaultdict、Counter、deque等。
- 解码数据:如何处理编码和解码过程中的数据。
- 自定义变体:介绍如何创建和使用用户自定义的数据结构。
3. 文件访问
- 文件名:处理文件和路径名相关的操作。
- 元数据:管理文件的额外信息,如权限、创建时间等。
- 读取文件:介绍如何打开和读取文件中的数据。
- 临时文件:生成临时文件或目录的使用方法。
- 文件和目录:进行文件和目录的创建、删除、修改等操作。
4. 文本处理工具
- string模块:包含一系列字符串处理功能,用于字符串操作。
- 文本输入和输出:读写文本数据的方法和技巧。
- 比较值:文本比较的技术和工具,如difflib模块。
5. 内置对象和字符串服务
- exceptions:Python内置的异常类,用于错误处理。
- codecs:字符串编码和解码的模块。
- difflib:用于比较序列并找出序列之间的差异。
- string:处理文本的模块,包含各种字符串常量。
- StringIO和cStringIO:使用文件式API操作文本缓冲区。
- re:正则表达式处理模块。
- struct:处理二进制数据的模块。
- textwrap:文本格式化工具,可以用于格式化文本段落。
6. 数据类型
- datetime:用于处理日期和时间值的模块。
- calendar:操作日期的模块。
- collections:包含高级数据结构如Counter、OrderedDict等。
- heapq:提供堆排序算法,用于原地堆排序。
- bisect:维护已排序列表模块。
- sched:通用事件调度器。
- Queue:线程安全的先进先出队列实现。
- weakref:提供垃圾回收的弱引用模块。
- copy:对象复制模块。
- pprint:美化打印数据结构。
7. 数字和数学模块
- decimal:用于固定和浮点数的数学模块。
- fractions:处理有理数模块。
- functools:提供函数操作工具。
- itertools:迭代器函数,用于高效循环。
- operator:内置操作的函数接口。
- random:伪随机数生成器模块。
通过这些知识点,我们可以看到Python编程涉及的多种第三方库,这些库提供了丰富的功能和工具,以支持从数据处理到算法实现,再到系统编程的广泛需求。掌握这些库的使用,对于提升Python编程能力至关重要。同时,文档中也强调了参考文档对于学习和开发工作的重要性,文档是我们获取信息、解决问题的重要途径之一。

Python Module of the Week
Release 1.132
Doug Hellmann
April 30, 2017


CONTENTS
1 Data Persistence and Exchange 3
1.1 Serializing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Storing Serialized Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Relational Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Data Exchange Through Standard Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 In-Memory Data Structures 5
2.1 array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Decoding Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Custom Variations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 File Access 7
3.1 Filenames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Meta-data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Reading Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Temporary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.5 Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Text Processing Tools 9
4.1 string module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Text Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.3 Text Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.4 Comparing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5 Built-in Objects 11
5.1 exceptions – Built-in error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6 String Services 23
6.1 codecs – String encoding and decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
6.2 difflib – Compare sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.3 string – Working with text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.4 StringIO and cStringIO – Work with text buffers using file-like API . . . . . . . . . . . . . . . . . . 54
6.5 re – Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.6 struct – Working with Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
6.7 textwrap – Formatting text paragraphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7 Data Types 97
7.1 array – Sequence of fixed-type data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
i

7.2 datetime – Date/time value manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.3 calendar – Work with dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
7.4 collections – Container data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.5 heapq – In-place heap sort algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
7.6 bisect – Maintain lists in sorted order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.7 sched – Generic event scheduler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7.8 Queue – A thread-safe FIFO implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
7.9 weakref – Garbage-collectable references to objects . . . . . . . . . . . . . . . . . . . . . . . . . . 135
7.10 copy – Duplicate objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.11 pprint – Pretty-print data structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8 Numeric and Mathematical Modules 153
8.1 decimal – Fixed and floating point math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.2 fractions – Rational Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
8.3 functools – Tools for Manipulating Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
8.4 itertools – Iterator functions for efficient looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
8.5 math – Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
8.6 operator – Functional interface to built-in operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
8.7 random – Pseudorandom number generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
9 Internet Data Handling 213
9.1 base64 – Encode binary data into ASCII characters . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
9.2 json – JavaScript Object Notation Serializer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
9.3 mailbox – Access and manipulate email archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
9.4 mhlib – Work with MH mailboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
10 File Formats 233
10.1 csv – Comma-separated value files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
10.2 ConfigParser – Work with configuration files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
10.3 robotparser – Internet spider access control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
11 Cryptographic Services 255
11.1 hashlib – Cryptographic hashes and message digests . . . . . . . . . . . . . . . . . . . . . . . . . . 255
11.2 hmac – Cryptographic signature and verification of messages. . . . . . . . . . . . . . . . . . . . . . 258
12 File and Directory Access 263
12.1 os.path – Platform-independent manipulation of file names. . . . . . . . . . . . . . . . . . . . . . . 263
12.2 fileinput – Process lines from input streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
12.3 filecmp – Compare files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
12.4 tempfile – Create temporary filesystem resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
12.5 glob – Filename pattern matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
12.6 fnmatch – Compare filenames against Unix-style glob patterns. . . . . . . . . . . . . . . . . . . . . 285
12.7 linecache – Read text files efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
12.8 shutil – High-level file operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
12.9 dircache – Cache directory listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
13 Data Compression and Archiving 299
13.1 bz2 – bzip2 compression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
13.2 gzip – Read and write GNU zip files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
13.3 tarfile – Tar archive access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
13.4 zipfile – Read and write ZIP archive files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
13.5 zlib – Low-level access to GNU zlib compression library . . . . . . . . . . . . . . . . . . . . . . . . 326
14 Data Persistence 333
14.1 anydbm – Access to DBM-style databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
ii

14.2 dbhash – DBM-style API for the BSD database library . . . . . . . . . . . . . . . . . . . . . . . . . 335
14.3 dbm – Simple database interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
14.4 dumbdbm – Portable DBM Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
14.5 gdbm – GNU’s version of the dbm library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
14.6 pickle and cPickle – Python object serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
14.7 shelve – Persistent storage of arbitrary Python objects . . . . . . . . . . . . . . . . . . . . . . . . . 344
14.8 whichdb – Identify DBM-style database formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
14.9 sqlite3 – Embedded Relational Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
15 Generic Operating System Services 377
15.1 os – Portable access to operating system specific features. . . . . . . . . . . . . . . . . . . . . . . . 377
15.2 time – Functions for manipulating clock time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
15.3 getopt – Command line option parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
15.4 optparse – Command line option parser to replace getopt. . . . . . . . . . . . . . . . . . . . . . . . 402
15.5 argparse – Command line option and argument parsing. . . . . . . . . . . . . . . . . . . . . . . . . 414
15.6 logging – Report status, error, and informational messages. . . . . . . . . . . . . . . . . . . . . . . . 433
15.7 getpass – Prompt the user for a password without echoing. . . . . . . . . . . . . . . . . . . . . . . . 436
15.8 platform – Access system version information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
16 Optional Operating System Services 443
16.1 threading – Manage concurrent threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
16.2 mmap – Memory-map files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
16.3 multiprocessing – Manage processes like threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
16.4 readline – Interface to the GNU readline library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
16.5 rlcompleter – Adds tab-completion to the interactive interpreter . . . . . . . . . . . . . . . . . . . . 494
17 Unix-specific Services 495
17.1 commands – Run external shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
17.2 grp – Unix Group Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
17.3 pipes – Unix shell command pipeline templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
17.4 pwd – Unix Password Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
17.5 resource – System resource management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
18 Interprocess Communication and Networking 513
18.1 asynchat – Asynchronous protocol handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
18.2 asyncore – Asynchronous I/O handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
18.3 signal – Receive notification of asynchronous system events . . . . . . . . . . . . . . . . . . . . . . 528
18.4 subprocess – Work with additional processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
19 Internet Protocols and Support 545
19.1 BaseHTTPServer – base classes for implementing web servers . . . . . . . . . . . . . . . . . . . . . 545
19.2 cgitb – Detailed traceback reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
19.3 Cookie – HTTP Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
19.4 imaplib - IMAP4 client library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
19.5 SimpleXMLRPCServer – Implements an XML-RPC server. . . . . . . . . . . . . . . . . . . . . . . 582
19.6 smtpd – Sample SMTP Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
19.7 smtplib – Simple Mail Transfer Protocol client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
19.8 socket – Network Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
19.9 select – Wait for I/O Efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
19.10 SocketServer – Creating network servers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
19.11 urllib – simple interface for network resource access . . . . . . . . . . . . . . . . . . . . . . . . . . 637
19.12 urllib2 – Library for opening URLs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
19.13 urlparse – Split URL into component pieces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
19.14 uuid – Universally unique identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
19.15 webbrowser – Displays web pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
iii
剩余952页未读,继续阅读
资源推荐
资源评论
159 浏览量

165 浏览量
134 浏览量
192 浏览量
2019-07-18 上传
159 浏览量

173 浏览量
134 浏览量
136 浏览量
159 浏览量
136 浏览量
137 浏览量
170 浏览量
资源评论


feilie01
- 粉丝: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 智能家居开题报告(最新整理).pdf
- 浅论测绘工程制图中如何有效运用计算机技术论文.doc
- 青海省网络购物市场发展状况调查报告范文.doc
- 项目管理流程和规范样本.doc
- 中国网民网络信息安全状况调查报告.doc
- 关注网络安全预防网络诈骗党课图文精品.pptx
- 网络空间安全竞赛设备单一来源采购项目.doc
- 用矛盾的观点看待网络的利与弊PPT课件.ppt
- 数据库原理知识点总结-精华.docx
- 隐蔽工程验收记录(综合布线).doc
- 数据挖掘填空题复习资料.doc
- 计算机专业实习报告.docx
- PMP网上报名流程说明(不包含会员).ppt
- 算法设计与分析-变治法PPT课件.ppt
- 网络礼品选购平台商业企划书.docx
- 公司网络项目投标书.doc
安全验证
文档复制为VIP权益,开通VIP直接复制
