42

我目前知道两个工具:

  1. base64 编码器/解码器:

    python -m base64 -e <input
    python -m base64 -d <input

  2. json 验证器和漂亮的打印机

    python -m json.tool <input

其中输入可以是标准输入或文件。

我很好奇 SPL 是否还有其他以类似方式工作的工具?

4

4 回答 4

108

不是一个完整的列表...

编码

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>

UU编码/解码:

python -m uu [infile [outfile]] # encode
python -m uu -d [infile [outfile]] # decode

MIME 引用可打印编码/解码:

python -m mimify -e [infile [outfile]] # encode
python -m mimify -d [infile [outfile]] # decode

引用可打印的编码/解码:

python -m quopri [file] # encode
python -m quopri -d [file] # decode

压缩

压缩包:

python -m gzip [file] # compress
python -m gzip -d [file] # decompress

Zipfile提取等:

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

远程登录客户端:

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 REPL:

python -m code

Python字节码批处理编译器:

python -m compileall

Python 代码分析器:

python -m cProfile <script>
python -m profile <script>
python -m pstats <filename> # print profiling statistics

Python doctest 执行器:

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
于 2013-01-27T07:27:18.720 回答
30

许多。

$ grep "if __name__ == '__main__':" /usr/lib64/python2.7/* | wc -l
55

并不是所有的都可以作为过滤器,所以在运行之前检查有问题的模块。

于 2013-01-27T06:33:32.893 回答
12

Also, there is:

python -m this
于 2013-05-06T11:21:06.720 回答
1

Cheeseshop 上还有与 -m 兼容的软件包。试试“e”或“oo”:-)

于 2013-05-06T03:39:03.077 回答