什么;工具“;在Python标准库中提供
我目前知道两种工具:什么;工具“;在Python标准库中提供,python,Python,我目前知道两种工具: base64编码器/解码器: python-m base64-eMany 不过,并非所有模块都可以作为过滤器使用,因此在运行之前请检查有问题的模块。不是完整的列表 编码 Base64 en/解码: python -m base64 -d [file] python -m base64 -e [file] python -m mimify -e [infile [outfile]] # encode python -m mimify -d [infile [outfile]
python-m base64-eMany
不过,并非所有模块都可以作为过滤器使用,因此在运行之前请检查有问题的模块。不是完整的列表
编码
Base64 en/解码:
python -m base64 -d [file]
python -m base64 -e [file]
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
ROT-13 en/解码器:
python -m encodings.rot_13
Macintosh BinHex:
# binhex <file> to <file>.hqx, and unbinhex <file>.hqx to <file>.viahqx
python -m binhex <file>
MIME引用可打印en/解码:
python -m base64 -d [file]
python -m base64 -e [file]
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
引用可打印的en/解码:
python -m base64 -d [file]
python -m base64 -e [file]
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
压缩
GZip:
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
简单FTP客户端:
python -m ftplib host [-l<dir-to-list>] [-d<dir-to-cwd>] [-p] [file-to-retrieve]
列出POP3邮箱:
python -m poplib <server> <username> <password>
发送邮件消息(到本地主机):
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
纯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交互式调试器:
python -m pdb
从模块中提取Python类和方法:
python -m pyclbr <script>
杂项
日历(类似于cal
,但可以使用HTML和各种奇特的格式):
目录比较器:
python -m filecmp [-r] dir1 dir2 # -r for recursive directory compare
段落格式:
python -m formatter [file]
显示当前平台(如uname
但更简单):
奶酪店也有与-m兼容的包装。试试“e”或“oo”:-还有:
python -m this
+1太棒了。大开眼界。是的,这似乎是一个合理的模式。我想可能有一个网页描述了这些工具,但找不到。我想这是最接近的,但仍然是简单的一面。感谢有没有一个Mac OS X的等价物?grep“如果uuuu name_uuuuuu=''uuuuu main_uuuuu':“`python-c'导入操作系统;打印os.path.dirname(os.\uu文件)`/*\wc-l
。是的,OSX有wc
。别忘了检查其他引号样式,并使用递归grep——还有更多好东西,例如calandar.py:grep-rs“if.\uu name.\uuu==[\'\'”]\uu main.[\'\'\]:“/usr/lib/python2.7
感谢您明确地展示了示例并添加了说明。这是一个很好的参考。虽然其中很多都很方便,但请不要开始使用它们来代替真正的应用程序/命令。每当有人发出命令时,我都会很不高兴,我不想在bash脚本中看到python-m gzip-d文件而不是gunzip文件
。@NathanAdams几年后,我才发现这个。除了速度之外,还有什么理由使用本机工具而不是python脚本?python脚本似乎更易于移植,安装范围也更广。我认为gunzip比python(它是GNU程序库的一部分)更标准,因此它们不太可能改变,包括命令行参数。另一方面,Python开发人员似乎在发布时又快又松,喜欢改变(无论好坏)。gzip Python库可能不会改变——但我个人不希望依赖它(参见urllib)。我并不反对使用Python,但使用用C编写的gunzip似乎比将整个Python解释器旋转到内存中更符合逻辑。
python -m pdb
python -m pyclbr <script>
python -m pydoc <topic>
python -m pydoc -g # graphical browser
python -m pydoc -p <port> # start HTTP docs server on port
python -m timeit
python -m calendar
python -m filecmp [-r] dir1 dir2 # -r for recursive directory compare
python -m formatter [file]
python -m platform
python -m this