寫點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寫程序時涉及到傳參調試就可以用上面的方式。