1、使用函数
fire可非常简单快速地实现命令功能。
$pythonhello.py HelloWorld! $pythonhello.py--name=Prodesire HelloProdesire! $pythonhello.py--help INFO:Showinghelpwiththecommand'hello.py----help'. NAME hello.py SYNOPSIS hello.py<flags> FLAGS --name=NAME
2、使用类
使用函数是最简单的方式,如果想以更有组织的方式来实现,比如使用类,fire 也是支持的。
importfire classCalculator(object): """Asimplecalculatorclass.""" defdouble(self,number): return2*number deftriple(self,number): return3*number if__name__=='__main__': fire.Fire(Calculator)
以上就是python fire在函数和类中的应用,希望对大家有所帮助。更多Python高级指路:python高级
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
上一篇