VSCode Debug Click - Python Command-Line Applications

写点Python小脚本我喜欢用Visual Studio Code,够小够快。关于Python的配置就不多说了,请大家按照官方教程操作 Python with Visual Studio Code。在这里主要说要怎么调试用Python写的命令行程序。不知为何我设置launcher.json中的args参数无效,所以后面试验了下找到了通知的方法。
下面是我的一个Python小项目TTPassGen的部分代码:

import click

@click.command()
@click.option("--mode", show_default=True, default=0, type=click.INT, help="generation mode")
@click.argument("output", type=click.Path())
def cli(mode, output):
    pass

if __name__ == "__main__":
    cli.main(['--mode', 0, 'out.dict'])  #重点

cli()是正式的处理函数,我们用Click写程序时涉及到传参调试就可以用上面的方式。

猜你喜欢

转载自blog.csdn.net/tp7309/article/details/72587621