小编给大家分享一下python fire怎么在函数和类中应用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
python是什么意思
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)
以上是“python fire怎么在函数和类中应用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注天达云行业资讯频道!