码迷,mamicode.com
首页 > 编程语言 > 详细

python 命令行工具 fire

时间:2018-02-26 18:55:52      阅读:714      评论:0      收藏:0      [点我收藏+]

标签:sel   line   tor   ble   func   component   down   single   called   

简介

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

标签:sel   line   tor   ble   func   component   down   single   called   

原文地址:https://www.cnblogs.com/xiaomingtx/p/8474544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!