终端环境Python实用工具

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"
        }
    ]
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值