python 命令行工具 fire

时间:2023-11-09 17:41:08

简介

A library for automatically generating command line interfaces.

Python Fire is a library for automatically generating command line interfaces (CLIs) with a single line of code.

It will turn any Python module, class, object, function, etc. (any Python component will work!) into a CLI. It’s called Fire because when you call Fire(), it fires off your command.

安装

pip install fire

使用

例子

import fire

class Calculator(object):
"""A simple calculator class.""" def double(self, number):
print '2 *',number,'=',2 * number def doublekill(self, number, n):
print 'n:',n
print '2 *',number,'=',2 * number if __name__ == '__main__':
fire.Fire(Calculator)

执行结果python 命令行工具 fire