我遵循The Python Fire Guide并执行Grouping命令中的脚本。程序如下所示:
import fire
class IngestionStage(object):
def run(self):
return 'Ingesting! Nom nom nom...'
class DigestionStage(object):
def run(self, volume=1):
return ' '.join(['Burp!'] * volume)
def status(self):
return 'Satiated.'
class Pipeline(object):
def __init__(self):
self.ingestion = IngestionStage()
self.digestion = DigestionStage()
def run(self):
self.ingestion.run()
self.digestion.run()
if __name__ == '__main__':
fire.Fire(Pipeline)
但是,执行该命令后没有任何反应:
$ python3 example.py run
我在ubuntu 16.04和python 3.5.2上运行这个程序。fire包的版本是0.1.3。有人遇到过这个问题吗?
发布于 2019-08-14 01:13:47
谢谢你抓到这个。python3 example.py run
不打印任何内容的原因是Pipeline.run不返回任何内容。
如果您将Pipeline.run方法更新为:
def run(self):
return [
self.ingestion.run(),
self.digestion.run(),
]
然后,您将看到所需的输出:
$ python example.py run
Ingesting! Nom nom nom...
Burp!
我们将不得不更新指南。
https://stackoverflow.com/questions/52416746
复制相似问题