python fabric 的新手,不会 运行 基本代码

New to python fabric and not able to run basic code

我有一个没有的基本代码 运行:

def hello():
    print("uptime")

当我在终端运行下面的命令fab hello

我收到这个错误:

No idea what 'hello' is!

您很可能需要输入:

fab hello()

$ fab hello

问题是新的 fabric 任务方法(如此处讨论 - http://docs.fabfile.org/en/1.14/usage/tasks.html)是使用 @task 装饰器。您的代码的等效示例是:

from fabric import task

@task
def hello():
  print("uptime")

运行 fab hello 应该会产生预期的输出。

来源:https://github.com/fabric/fabric/issues/1854#issuecomment-414639606