Launch Python debugger while simultaneously executing module as script

前端 未结 5 1438
你的背包
你的背包 2020-12-14 09:21

When developing a Python package, it\'s very convenient to use the -m option to run modules inside the package as scripts for quick testing. For example, for

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 09:43

    After experimenting with this for quite some time, it turns out that this approach actually works:

    python -c "import runpy; import pdb; pdb.runcall(runpy.run_module, 'somepackage.somemodule', run_name='__main__')"
    

    For some reason, the use of pdb.runcall over pdb.run is important.

提交回复
热议问题