你一定用过很多 linux 的命令行工具,并且觉得这些工具很酷。
Python 能编写这些工具吗?
答案是肯定的。今天我们就来看看如何用 python 编写命令行工具。
实现方式
如何接受cmd中输入的参数,需要用到的就是命令行解析工具。
python中有很多命令行解析库,主要有如下几种
-
sys.argv
-
argparse 库
-
click 库
-
fire 库(这是一个神器)
2018年2月14日大约 3 分钟
你一定用过很多 linux 的命令行工具,并且觉得这些工具很酷。
Python 能编写这些工具吗?
答案是肯定的。今天我们就来看看如何用 python 编写命令行工具。
如何接受cmd中输入的参数,需要用到的就是命令行解析工具。
python中有很多命令行解析库,主要有如下几种
sys.argv
argparse 库
click 库
fire 库(这是一个神器)
Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.
Python Fire is a simple way to create a CLI in Python.
Python Fire is a helpful tool for developing and debugging Python code.