python小技巧
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python小技巧相关的知识,希望对你有一定的参考价值。
命令行启动简单的httpserver:
python3:
$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.1.21.242 - - [27/Sep/2017 18:24:34] "GET / HTTP/1.1" 200 -
10.1.21.242 - - [27/Sep/2017 18:24:34] code 404, message File not found
10.1.21.242 - - [27/Sep/2017 18:24:34] "GET /favicon.ico HTTP/1.1" 404 -
10.1.21.242 - - [27/Sep/2017 18:24:37] "GET /%E5%85%AC%E5%8F%B8%E5%8A%9E%E5%85%AC%E7%BD%91%E7%BF%BB%E5%A2%99%E9%85%8D%E7%BD%AE%E6%96%B9%E6%B3%95.docx HTTP/1.1" 200 -
10.10.2.242 - - [27/Sep/2017 18:27:11] "GET / HTTP/1.1" 200 -
python2:
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
10.1.21.242 - - [27/Sep/2017 18:31:46] "GET / HTTP/1.1" 200 -
10.1.21.242 - - [27/Sep/2017 18:31:47] "GET / HTTP/1.1" 200 -
格式化输出:
$ echo ‘{"a":1, "b":2}‘ | python -m json.tool
{
"a": 1,
"b": 2
}
快速验证模块是否已经安装:
# python -c "import paramiko"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named paramiko
# python3 -c "import paramiko"
以上是关于python小技巧的主要内容,如果未能解决你的问题,请参考以下文章