AttributeError: module 'click' has no attribute 'command'

AttributeError: module 'click' has no attribute 'command'

最近接触到 python 的命令行模块 click,然而按照官方文档内容

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name', help='The person to greet.')
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for x in range(count):
        click.echo('Hello %s!' % name)

if __name__ == '__main__':
    hello()

运行的时候一直提示 AttributeError: module 'click' has no attribute 'command'

百思不得其解啊,后来终于在网上找到了原因,是因为我把上述测试的文件命名为 click.py 了,这种以模块名命名文件在 python 中是一个大忌啊,会使文件在 import click 模块的时候使用我们创建的 click.py 文件。

解决方法:

click.py 文件换成其他的名字即可。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容