美文网首页
终端环境Python实用工具

终端环境Python实用工具

作者: 阿基米德来了 | 来源:发表于2019-09-30 16:23 被阅读0次

1、Python下载服务器

可以在当前目录下快速启动一个文件下载服务器,供其他机器下载文件

#python2环境
python -m SimpleHTTPServer
#python3环境
python3 -m http.server

该下载服务器会默认打开8000端口,现在只需要访问http://ip:8000就可以方便的下载文件了
另外也可以自己修改绑定地址和端口

root@ubuntu_sever:~$ python3 -m http.server -h
usage: server.py [-h] [--cgi] [--bind ADDRESS] [port]

positional arguments:
  port                  Specify alternate port [default: 8000]

optional arguments:
  -h, --help            show this help message and exit
  --cgi                 Run as CGI Server
  --bind ADDRESS, -b ADDRESS
                        Specify alternate bind address [default: all
                        interfaces]

2、字符串转json

python提供了一个json格式转换,这下我们遇到json字符串可以不用再去第三方网址了

python -m json.tool

使用如下

#将json字符串重定向到json.tool即可
root@ubuntu_sever:~$ echo '{"employees":[{"firstName":"Bill","lastName":"Gates"},{"firstName":"George","lastName":"Bush"},{"firstName":"Thomas","lastName":"Carter"}]}' \
> | python -m json.tool
{
    "employees": [
        {
            "firstName": "Bill",
            "lastName": "Gates"
        },
        {
            "firstName": "George",
            "lastName": "Bush"
        },
        {
            "firstName": "Thomas",
            "lastName": "Carter"
        }
    ]
}

相关文章

网友评论

      本文标题:终端环境Python实用工具

      本文链接:https://www.haomeiwen.com/subject/iofhpctx.html