单击 main() 中的错误 "takes no arguments"
Click error "takes no arguments" in main()
我遇到了我认为是由于点击引起的问题。我正在尝试 运行 这段代码,并且我将 运行ning 保持在相同的回溯类型错误中,说明一个参数正在传递给 main()。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import boto
import boto.ec2
import click
@click.command()
@click.option('--region', '-r', default='us-west-2', help='AWS Region')
def main():
try:
ec2 = boto.ec2.connect_to_region(region)
except Exception, error:
print("Boto Error: %s" ) % str(error)
else:
print("It's working!")
finally:
sys.exit(1)
if __name__ == "__main__":
main()
这段代码看起来很简单,所以我认为 click 在这里做了一些事情来防止它正常工作?
Traceback (most recent call last):
File "test.py", line 21, in <module>
main()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
TypeError: main() takes no arguments (1 given)
我不熟悉 click
模块,但从文档中可以看出,您应该将 def main():
更改为 def main(region):
,因为您希望函数接受参数您是从命令行传递的。
我遇到了我认为是由于点击引起的问题。我正在尝试 运行 这段代码,并且我将 运行ning 保持在相同的回溯类型错误中,说明一个参数正在传递给 main()。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import boto
import boto.ec2
import click
@click.command()
@click.option('--region', '-r', default='us-west-2', help='AWS Region')
def main():
try:
ec2 = boto.ec2.connect_to_region(region)
except Exception, error:
print("Boto Error: %s" ) % str(error)
else:
print("It's working!")
finally:
sys.exit(1)
if __name__ == "__main__":
main()
这段代码看起来很简单,所以我认为 click 在这里做了一些事情来防止它正常工作?
Traceback (most recent call last):
File "test.py", line 21, in <module>
main()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 700, in __call__
return self.main(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 680, in main
rv = self.invoke(ctx)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 873, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 508, in invoke
return callback(*args, **kwargs)
TypeError: main() takes no arguments (1 given)
我不熟悉 click
模块,但从文档中可以看出,您应该将 def main():
更改为 def main(region):
,因为您希望函数接受参数您是从命令行传递的。