Reputation: 2679
I am running a python script. In this script, I import a function from another module like:
from preprocessing import train_batch
the train_batch
function is called in the script I am running. Now to check the train_batch
in more details, I find the preprocessing.py
and insert pdb.set_trace()
in train_batch
in the preprocessing.py
, but it doesn't work.
So I want to ask: can I use pdb.set_trace()
in an imported module? If I can, then this must mean the module I found is wrong and I need to find the right place. If I cannot, then is there any good way to check imported function if necessary?
Upvotes: 3
Views: 2726
Reputation: 51807
You can do a import pdb; pdb.set_trace()
anywhere in Python code*. If it "doesn't work" I assume you mean that you never dropped into pdb. That means that line of code is not being executed.
You can use the 's' command in pdb to step into code, even if it's not your own. As long as it's Python and not C code, you should be just fine. I'm not sure what happens for the C code.
Upvotes: 3
Reputation: 12213
Yes. pdb.set_trace()
is just a function call; you can place it anywhere that you can put any other function call.
Upvotes: -1