码迷,mamicode.com
首页 > 编程语言 > 详细

python小技巧

时间:2017-09-27 20:33:58      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:cal   rac   col   imp   style   named   ram   param   import   

命令行启动简单的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小技巧

标签:cal   rac   col   imp   style   named   ram   param   import   

原文地址:http://www.cnblogs.com/helloworld899/p/7603321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!