【问题标题】:Pass arguments to command groups, python fire将参数传递给命令组,python fire
【发布时间】:2021-09-21 19:21:20
【问题描述】:

如何将参数valcode 传递给get

  • 到目前为止的代码

import fire

class Get:

    def __init__(self, val="no", code=""):

        self.val = val
        self.code = code


    def get(self):
        return f"called get {self.val} {self.code}"

    def get_many(self):
        return f"called get many {self.val}"


class Pipeline:

    def __init__(self,):
        self.get = Get()

def main():
    fire.Fire(Pipeline)
  • 我遇到的错误

$> my_p get --code="test" --val="yes" get

ERROR: Could not consume arg: --code=test
Usage: my_p get get <command>

【问题讨论】:

    标签: python python-3.x command-line-arguments python-fire


    【解决方案1】:

    根据https://github.com/google/python-fire/blob/master/docs/guide.md#version-4-firefireclass

    你需要改变:

    self.get = Get
    

    此外,我建议不要在 Get 类的“get”函数中使用相同的名称。很混乱。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 2017-10-22
      • 2021-10-20
      • 2019-10-12
      • 1970-01-01
      相关资源
      最近更新 更多