python 有 "内置电池" 的称号, 安装 Python3 后, 你可以无需编码, 直接通过命令行使用 python3 部分 "内置电池" 的功能, 这里介绍两个很好用的 "电池" 模块~
1 秒搭建下载服务器
这是一个非常老司机的操作, 适合在公司同事之间实时共享资源, 管理员进入文件夹 test-http, 输入
python -m http.server
即可快速开启服务, 然后让与处于同一内网的同事, 访问管理员的 ip 和对应端口, 就可以下载 test-http 文件夹内的文件.
- python -m http.server
- mac os x (扮演管理员的角色, ip 为 192.168.214.1)
centos 7 (扮演同事的角色, ip 为 192.168.214.160)
使用 mac os x 的管理员可以查看来访者 ip 地址
压缩 / 解压 zip 文件
在 linux 中, 并没有内置压缩 / 解压 zip 格式的工具, 但在 mac 和 windows 中 zip 却非常流行, 如果你安装了 python3, 就可以使用 python3 的 "内置电池" zipfile 为 zip 格式进行压缩 / 解压的操作, 非常好用, 示例如下:
测试方法: 先根据文件夹 test-zipfile 创建压缩文件 test-zipfile.zip, 然后删除文件夹 test-file, 然后根据压缩文件 test-zipfile.zip 创建文件夹 test-zipfile
- # 根据文件夹 test-zipfile 创建压缩文件 test-zipfile.zip
- python -m zipfile -c test-zipfile.zip test-zipfile
- # 根据压缩文件 test-zipfile.zip 创建文件夹 test-zipfile
- python -m zipfile -e test-zipfile.zip test-zipfile
来源: http://www.jianshu.com/p/85cd47a6ef85