python fire如何在函数和类中应用

323次阅读
没有评论

python

1、使用函数

fire可非常简单快速地实现命令功能。

$ python hello.py
Hello World!
$ python hello.py --name=Prodesire
Hello Prodesire!
$ python hello.py --help
INFO: Showing help with the command 'hello.py -- --help'.
 
NAME
    hello.py
 
SYNOPSIS
    hello.py <flags>
 
FLAGS
    --name=NAME

2、使用类

使用函数是最简单的方式,如果想以更有组织的方式来实现,比如使用类,fire 也是支持的。

import fire
 
class Calculator(object):
  """A simple calculator class."""
 
  def double(self, number):
    return 2 * number
 
  def triple(self, number):
    return 3 * number
 
if __name__ == '__main__':
  fire.Fire(Calculator)
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-07-13发表,共计539字。
新手QQ群:570568346,欢迎进群讨论 Python51学习