【问题标题】:Python Fire doesn't parse single argument with whitespaces correctlyPython Fire 无法正确解析带有空格的单个参数
【发布时间】:2019-05-09 07:50:57
【问题描述】:

我有这样的功能-

def f(arg)
  print(arg)

尝试像这样使用 Python Fire 传递参数 -

f hello there

输出 -

hello

【问题讨论】:

    标签: python command-line command-line-interface command-line-arguments python-fire


    【解决方案1】:

    将输入包含在转义引号中后它起作用了 -

    f \"hello there\"
    

    输出 -

    hello there
    

    【讨论】:

    • 那是因为没有引号它会将hello 作为第一个参数,there 作为第二个参数。用引号将它绑定在一起形成单个参数hello there
    • 这个 still 有两个参数:转义的引号只是普通字符,所以它们不会转义hellothere 之间的空格。如果这产生了您声称的输出,那么您在原始问题中遗漏了一些上下文。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2019-03-01
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多