Python标准库中有哪些“工具”?
我现在知道有两个工具:
base64 编码器/解码器:
python -m base64 -e <输入
python -m base64 -d <输入
json 验证器和格式化工具:
python -m json.tool <输入
这里的输入可以是标准输入(stdin)或者文件。
我想知道还有没有其他类似的工具可以通过 SPL 使用?
4 个回答
12
还有:
python -m this
109
这不是一个完整的列表...
编码
Base64 编码和解码:
python -m base64 -d [file]
python -m base64 -e [file]
ROT-13 编码和解码:
python -m encodings.rot_13
Macintosh BinHex 编码:
# binhex <file> to <file>.hqx, and unbinhex <file>.hqx to <file>.viahqx
python -m binhex <file>
UUencode 编码和解码:
python -m uu [infile [outfile]] # encode
python -m uu -d [infile [outfile]] # decode
MIME quoted-printable 编码和解码:
python -m mimify -e [infile [outfile]] # encode
python -m mimify -d [infile [outfile]] # decode
Quoted-printable 编码和解码:
python -m quopri [file] # encode
python -m quopri -d [file] # decode
压缩
GZip:
python -m gzip [file] # compress
python -m gzip -d [file] # decompress
解压 Zip 文件等:
python -m zipfile -l <file> # list
python -m zipfile -t <file> # test
python -m zipfile -e <file> <dir> # extract
python -m zipfile -c <file> sources... # create
互联网
HTTP 服务器:
python -m BaseHTTPServer
python -m CGIHTTPServer
python -m SimpleHTTPServer
简单的 FTP 客户端:
python -m ftplib host [-l<dir-to-list>] [-d<dir-to-cwd>] [-p] [file-to-retrieve]
提取 HTML 文本:
python -m htmllib <file>
JSON 验证器和美化工具:
python -m json.tool [infile [outfile]]
列出 POP3 邮箱:
python -m poplib <server> <username> <password>
SMTP 服务器:
python -m smtpd
发送邮件(到本地服务器):
python -m smtplib
Telnet 客户端:
python -m telnetlib [host [port]]
MIME 类型/扩展名数据库:
python -m mimetypes file.ext # print type for filename
python -m mimetypes -e mime/type # print extension for type
打开网页浏览器:
python -m webbrowser -n <url> # new window
python -m webbrowser -t <url> # new tab
反重力:
python -m antigravity
Python
纯 Python 交互式环境:
python -m code
Python 字节码批量编译器:
python -m compileall
Python 代码性能分析工具:
python -m cProfile <script>
python -m profile <script>
python -m pstats <filename> # print profiling statistics
Python 文档测试执行器:
python -m doctest <script>
Python 性能基准测试:
python -m test.pystone [iterations]
python -m hotshot.stones
Python 交互式调试器:
python -m pdb
从模块中提取 Python 类和方法:
python -m pyclbr <script>
Python 文档浏览器:
python -m pydoc <topic>
python -m pydoc -g # graphical browser
python -m pydoc -p <port> # start HTTP docs server on port
Python 代码片段计时器:
python -m timeit
其他
日历(像 cal
,但可以做 HTML 和各种花哨的格式):
python -m calendar
目录比较工具:
python -m filecmp [-r] dir1 dir2 # -r for recursive directory compare
段落格式化:
python -m formatter [file]
显示当前平台(像 uname
,但更简单):
python -m platform
30
有很多。
$ grep "if __name__ == '__main__':" /usr/lib64/python2.7/* | wc -l
55
不过并不是所有的都能作为过滤器使用,所以在运行之前要仔细检查一下相关模块。