logo资料库

Python 标准库 中文版.pdf

第1页 / 共329页
第2页 / 共329页
第3页 / 共329页
第4页 / 共329页
第5页 / 共329页
第6页 / 共329页
第7页 / 共329页
第8页 / 共329页
资料共329页,剩余部分请下载后查看
Python Standard Library 翻译: Python 江湖群 10/06/07 20:10:08 编译 • 0.1. 关于本书 • 0.2. 代码约定 • 0.3. 关于例子 • 0.4. 如何联系我们 1. 核心模块 o 1.1. 介绍 o 1.2. _ _builtin_ _ 模块 o 1.3. exceptions 模块 o 1.4. os 模块 o 1.5. os.path 模块 o 1.6. stat 模块 o 1.7. string 模块 o 1.8. re 模块 o 1.9. math 模块 o 1.10. cmath 模块 o 1.11. operator 模块 o 1.12. copy 模块 o 1.13. sys 模块 o 1.14. atexit 模块 o 1.15. time 模块 o 1.16. types 模块 o 1.17. gc 模块 o 2.1. 概览 o 2.2. fileinput 模块 o 2.3. shutil 模块 o 2.4. tempfile 模块 o 2.5. StringIO 模块 o 2.6. cStringIO 模块 o 2.7. mmap 模块 o 2.8. UserDict 模块 o 2.9. UserList 模块 o 2.10. UserString 模块 2. 更多标准模块
3. 线程和进程 4. 数据表示 o 2.11. traceback 模块 o 2.12. errno 模块 o 2.13. getopt 模块 o 2.14. getpass 模块 o 2.15. glob 模块 o 2.16. fnmatch 模块 o 2.17. random 模块 o 2.18. whrandom 模块 o 2.19. md5 模块 o 2.20. sha 模块 o 2.21. crypt 模块 o 2.22. rotor 模块 o 2.23. zlib 模块 o 2.24. code 模块 o 3.1. 概览 o 3.2. threading 模块 o 3.3. Queue 模块 o 3.4. thread 模块 o 3.5. commands 模块 o 3.6. pipes 模块 o 3.7. popen2 模块 o 3.8. signal 模块 o 4.1. 概览 o 4.2. array 模块 o 4.3. struct 模块 o 4.4. xdrlib 模块 o 4.5. marshal 模块 o 4.6. pickle 模块 o 4.7. cPickle 模块 o 4.8. copy_reg 模块 o 4.9. pprint 模块 o 4.10. repr 模块 o 4.11. base64 模块 o 4.12. binhex 模块 o 4.13. quopri 模块 o 4.14. uu 模块 o 4.15. binascii 模块 5. 文件格式 o 5.1. 概览 o 5.2. xmllib 模块 o 5.3. xml.parsers.expat 模块 o 5.4. sgmllib 模块
o 5.5. htmllib 模块 o 5.6. htmlentitydefs 模块 o 5.7. formatter 模块 o 5.8. ConfigParser 模块 o 5.9. netrc 模块 o 5.10. shlex 模块 o 5.11. zipfile 模块 o 5.12. gzip 模块 6. 邮件和新闻消息处理 o 6.1. 概览 o 6.2. rfc822 模块 o 6.3. mimetools 模块 o 6.4. MimeWriter 模块 o 6.5. mailbox 模块 o 6.6. mailcap 模块 o 6.7. mimetypes 模块 o 6.8. packmail 模块 o 6.9. mimify 模块 o 6.10. multifile 模块 7. 网络协议 o 7.1. 概览 o 7.2. socket 模块 o 7.3. select 模块 o 7.4. asyncore 模块 o 7.5. asynchat 模块 o 7.6. urllib 模块 o 7.7. urlparse 模块 o 7.8. cookie 模块 o 7.9. robotparser 模块 o 7.10. ftplib 模块 o 7.11. gopherlib 模块 o 7.12. httplib 模块 o 7.13. poplib 模块 o 7.14. imaplib 模块 o 7.15. smtplib 模块 o 7.16. telnetlib 模块 o 7.17. nntplib 模块 o 7.18. SocketServer 模块 o 7.19. BaseHTTPServer 模块 o 7.20. SimpleHTTPServer 模块 o 7.21. CGIHTTPServer 模块 o 7.22. cgi 模块 o 7.23. webbrowser 模块 8. 国际化
o 8.1. locale 模块 o 8.2. unicodedata 模块 o 8.3. ucnhash 模块 9. 多媒体相关模块 o 9.1. 概览 o 9.2. imghdr 模块 o 9.3. sndhdr 模块 o 9.4. whatsound 模块 o 9.5. aifc 模块 o 9.6. sunau 模块 o 9.7. sunaudio 模块 o 9.8. wave 模块 o 9.9. audiodev 模块 o 9.10. winsound 模块 10.数据储存 o 10.1. 概览 o 10.2. anydbm 模块 o 10.3. whichdb 模块 o 10.4. shelve 模块 o 10.5. dbhash 模块 o 10.6. dbm 模块 o 10.7. dumbdbm 模块 o 10.8. gdbm 模块 11.工具和实用程序 o 11.1. dis 模块 o 11.2. pdb 模块 o 11.3. bdb 模块 o 11.4. profile 模块 o 11.5. pstats 模块 o 11.6. tabnanny 模块 12.其他模块 o 12.1. 概览 o 12.2. fcntl 模块 o 12.3. pwd 模块 o 12.4. grp 模块 o 12.5. nis 模块 o 12.6. curses 模块 o 12.7. termios 模块 o 12.8. tty 模块 o 12.9. resource 模块 o 12.10. syslog 模块 o 12.11. msvcrt 模块 o 12.12. nt 模块 o 12.13. _winreg 模块
o 12.14. posix 模块 13.执行支持模块 o 13.1. dospath 模块 o 13.2. macpath 模块 o 13.3. ntpath 模块 o 13.4. posixpath 模块 o 13.5. strop 模块 o 13.6. imp 模块 o 13.7. new 模块 o 13.8. pre 模块 o 13.9. sre 模块 o 13.10. py_compile 模块 o 13.11. compileall 模块 o 13.12. ihooks 模块 o 13.13. linecache 模块 o 13.14. macurl2path 模块 o 13.15. nturl2path 模块 o 13.16. tokenize 模块 o 13.17. keyword 模块 o 13.18. parser 模块 o 13.19. symbol 模块 o 13.20. token 模块 14.其他模块 o 14.1. 概览 o 14.2. pyclbr 模块 o 14.3. filecmp 模块 o 14.4. cmd 模块 o 14.5. rexec 模块 o 14.6. Bastion 模块 o 14.7. readline 模块 o 14.8. rlcompleter 模块 o 14.9. statvfs 模块 o 14.10. calendar 模块 o 14.11. sched 模块 o 14.12. statcache 模块 o 14.13. grep 模块 o 14.14. dircache 模块 o 14.15. dircmp 模块 o 14.16. cmp 模块 o 14.17. cmpcache 模块 o 14.18. util 模块 o 14.19. soundex 模块 o 14.20. timing 模块 o 14.21. posixfile 模块
o 14.22. bisect 模块 o 14.23. knee 模块 o 14.24. tzparse 模块 o 14.25. regex 模块 o 14.26. regsub 模块 o 14.27. reconvert 模块 o 14.28. regex_syntax 模块 o 14.29. find 模块 15.Py 2.0 后新增模块 16.后记 "We'd like to pretend that 'Fredrik' is a role, but even hundreds of volunteers couldn't possibly keep up. No, 'Fredrik' is the result of crossing an http server with a spam filter with an emacs whatsit and some other stuff besides." -Gordon McMillan, June 1998 Python 2.0 发布附带了一个包含 200 个以上模块的可扩展的标准库. 本书简要 地介绍每个模块并提供至少一个例子来说明如何使用它. 本书一共包含 360 个 例子. 0.1. 关于本书 "Those people who have nothing better to do than post on the Internet all day long are rarely the ones who have the most insights." - Jakob Nielsen, December 1998 五年前我偶然遇到了 Python, 开始了我的 Python 之旅, 我花费了大量的时间 在 comp.lang.python 新闻组里回答问题. 也许某个人发现一个模块正是他想 要的, 但是却不知道如何使用它. 也许某个人为他的任务挑选的不合适的模块. 也许某个人已经厌倦了发明新轮子. 大多时候, 一个简短的例子要比一份手册 文档更有帮助. 本书是超过 3,000 个新闻组讨论的精华部分, 当然也有很多的新脚本, 为了涵 盖标准库的每个角落. 我尽力使得每个脚本都易于理解, 易于重用代码. 我有意缩短注释的长度, 如 果你想更深入地了解背景, 那么你可以参阅每个 Python 发布中的参考手册. 本书的重要之处在于范例代码. 我们欢迎任何评论, 建议, 以及 bug 报告, 请将它们发送到 fredrik@pythonware.com . 我将阅读尽我所能阅读所有的邮件, 但可能回复不 是那么及时.
本书的相关更新内容以及其他信息请访问 http://www.pythonware.com/people/fredrik/librarybook.htm 为什么没有 Tkinter? 本书涵盖了整个标准库, 除了(可选的)Tkinter ui(user-interface : 用户界面) 库. 有很多原因, 更多是因为时间, 本书的空间, 以及我正在写另一本关于 Tkinter 的书. 关于这些书的信息, 请访问 http://www.pythonware.com/people/fredrik/tkinterbook.htm . (不用看了, 又一 404) 产品细节 本书使用 DocBook SGML 编写, 我使用了一系列的工具, 包括 Secret Labs' PythonWorks, Excosoft Documentor, James Clark's Jade DSSSL processor, Norm Walsh's DocBook stylesheets, 当然,还有一些 Python 脚本. 感谢帮忙校对的人们: Tim Peters, Guido van Rossum, David Ascher, Mark Lutz, 和 Rael Dornfest, 以及 PythonWare 成员: Matthew Ellis, H?kan Karlsson, 和 Rune Uhlin. 感谢 Lenny Muellner, 他帮助我把 SGML 文件转变为你们现在所看到的这本书, 以及 Christien Shangraw, 他将那些代码文件集合起来做成了随书 CD (可以在 http://examples.oreilly.com/pythonsl 找到, 竟然没有 404, 奇迹). 0.2. 代码约定 本书使用以下习惯用法: 斜体 用于文件名和命令. 还用于定义术语. 等宽字体 e.g. Python 用于代码以及方法,模块,操作符,函数,语句,属性等的名称. 等宽粗体 用于代码执行结果. 0.3. 关于例子
除非提到,所有例子都可以在 Python 1.5.2 和 Python 2.0 下运行. 能不能在 Python 2.4/2.5 下执行.....看参与翻译各位的了. 除了一些平台相关模块的脚本, 所有例子都可以在 Windows, Solaris, 以及 Linux 下正常执行. 所有代码都是有版权的. 当然,你可以自由地使用这些这些模块,别忘记你是从 哪得到(?学会)这些的. 大多例子的文件名都包含它所使用的模块名称,后边是 "-example- " 以及一个 唯一的"序号". 注意有些例子并不是按顺序出现的, 这是为了匹配本书的较早 版本 - (the eff-bot guide to) The Standard Python Library . 你可以在网上找到本书附带 CD 的内容 (参阅 http://examples.oreilly.com/pythonsl ). 更多信息以及更新内容参阅 http://www.pythonware.com/people/fredrik/librarybook.htm . (ft, 又一 404. 大家一定不要看~) 0.4. 如何联系我们 Python 江湖 QQ 群: 43680167 Feather (校对) QQ: 85660100 1. 核心模块 "Since the functions in the C runtime library are not part of the Win32 API, we believe the number of applications that will be affected by this bug to be very limited." - Microsoft, January 1999 1.1. 介绍 Python 的标准库包括了很多的模块, 从 Python 语言自身特定的类型和声明, 到一些只用于少数程序的不著名的模块. 本章描述了一些基本的标准库模块. 任何大型 Python 程序都有可能直接或间 接地使用到这类模块的大部分.
分享到:
收藏