开发者

how to load a module within python debugger

开发者 https://www.devze.com 2022-12-30 12:31 出处:网络
This looks like something simple but I could not find the answer so far - I have just learnt python and need to start learning pdb. In my module I have the usual if __name__ == __main_ trick to execu

This looks like something simple but I could not find the answer so far -

I have just learnt python and need to start learning pdb. In my module I have the usual if __name__ == __main_ trick to execute some code when the module is run as a program.

So far I have been running it via python -m mymod arg1 arg2 syntax

Now I want to do exactly the same thing from inside pdb. Normally in C, I would just do gdb mybinary followed by run arg1 arg2

But I cannot figure out how to achieve the same thing in pdb.

I am sure there has to be a simple way to achieve this but it is taking me too long to search for it..

Thanks f开发者_StackOverflowor your help!


Try:

python -m pdb mymod.py arg1 arg2

That should start up pdb debugging mymod.py (if mymod.py is not in the current directory then you'll have to specify the path).

Alternatively set a breakpoint in your code where you want to start debugging. The usual way to get a breakpoint into pdb is:

if somecondition:
    import pdb; pdb.set_trace()

You can make the condition whatever is convenient to ensure the breakpoint doesn't trigger too soon.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号