首页 > 解决方案 > 单击命令不再是功能

问题描述

应用@click.command()装饰器后,被装饰的函数变为 aCommand并且不能再作为普通函数调用。但是,它仍然是可调用的,如果我将参数作为字符串列表传递,它似乎可以工作。

import click
@click.command()
@click.argument('info', nargs=-1)
def hello(info):
    print(info)

hello(['asdf'])

这有效,返回(u'asdf')。但是,当我这样做时:

hello([1234])它失败了TypeError: object of type 'int' has no len()。那么我应该将 aCommand视为它自己的东西,并且永远不要尝试通过导入来调用它吗?

标签: pythonclick

解决方案


推荐阅读