#!/usr/bin/env python3
import click
@click.command()
@click.option('--desiredrange', '-r', default=1)
def main(desiredrange):
print(desiredrange)
print('Abu can cn')
main()
print('!')
运行上面的代码会在终端中显示以下内容:
1
Abu can cn
但我不明白
!
This scenario is true for other variations of code that include ANYTHING after the main() function. The script exits after executing this function. This is also true for any function i.e. if I placed the print('!') inside another function, then called that function after main(), the script exits after main(), ignoring the second function.
如果我删除了‘Click’,则代码如下所示:
#!/usr/bin/env python3
def main():
print(1)
print('Abu can cn')
main()
print('!')
我将把以下内容打印到航站楼:
1
Abu can cn
!
我可以在main()之后执行其他函数,以及其他命令.我使用./script.py(应用的chmod+x script.py)从终端运行该脚本.我也没有从这两个场景中得到任何错误.
这是为什么?