Python模块 - fire
fire是python中用于生成命令行界面(Command Line Interfaces, CLIs)的工具,不需要做任何额外的工作,只需要从主模块中调用fire.Fire(),
它会自动将你的代码转化为CLI,Fire()的参数可以说任何的python对象
用法1
import fire def add(a, b): count = a + b return count if __name__ == '__main__': fire.Fire(add)
python a.py 1 3
用法2 import fire def add(a, b): count = a + b return count def sub(a, b): result = a - b return result if __name__ == '__main__': fire.Fire()
python a.py add 2 3
用法3
import fire class Calculator(object): def add(self, a, b): count = a + b return count def sub(self, a, b): result = a - b return result if __name__ == '__main__': fire.Fire(Calculator)
python a,py add 2 4