python 命令行工具 fire

Posted xiaomingtx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 命令行工具 fire相关的知识,希望对你有一定的参考价值。

简介

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的主要内容,如果未能解决你的问题,请参考以下文章