I have a python script that takes input arguments and runs in response to the following command in terminal (bash, Mac OSX).
python test.py arg1 arg2
Is there a good way to run the same script in debug mode without editing the code to include import pdb
and pdb.set_trace()
?
For example, if I'm using iPython console, I can do this by the following:
%run -d test.py arg1 arg2
This is pretty straightforward, isn't it? To achieve the same thing in terminal, I thought the following might work, but it did not:
python -c "import pdb; import sys; sys.argv = ['test.py', arg1, arg2];pdb.run('test.py')"
The code ran with the arguments, but not in pdb
's debugging mode. Is it just hard to do and I should stick with pdb.set_trace
or iPython's %run -d
?
Try:
python -m pdb test.py arg1 arg2
Running python -m pdb
runs pdb
as a script. If test.py
is somewhere in your path rather than your current working directory, this can be a helpful substitute:
python -m pdb "$(which test.py)" arg1 arg2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With