How to debug a Python module run with python -m from the command line?

后端 未结 6 524
后悔当初
后悔当初 2020-12-09 15:20

I know that a Python script can be debugged from the command line with

python -m pdb my_script.py

if my_script.py is a script

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 15:52

    According to the python command-line manpage the -m flag does the following:

    Searches sys.path for the named module and runs the corresponding .py file as a script.

    Given this, I would feel confident debugging by running the .py file as per your first example. One thing to keep in mind is that -m searches sys.path. Luckily, python looks at the current working directory first, so as long as the .py you are debugging is in your cwd, python -m module and python module.py equivalent.

提交回复
热议问题