Pyl debug point equivalent to perl $ db :: single = 1

I am a Perl programmer learning Python. I am writing my code in debugging emacs using python -m pdb script.pywith Python 2.7.3.

I would like to know what is equivalent to python in Perl, adding python $DB::single=1;1;to a specific line of code, so when you start the debugger it will stop there, even if it is a different source code from where the file starts (for example, the code line in the library is used script.py).

Any ideas?

EDITED: after watching pdb.set_trace()or ipdb.set_trace(), I think they are good solutions, but not 100% identical to the behavior $DB::single=1;1;. This, I would like the breakpoint to be on the set_trace line, and not on the next line. This is done in Perl $DB::single=1;by adding another statement on the same line: 1;what makes it $DB::single=1;1;.

Using set_trace(), I get a breakpoint in the line after the statement, even if I add it after it 1;. Still not fully understanding how Python treats strings with multiple statements compared to Perl.

Is anyone

enter image description here

Any ideas?

+3
source share
2 answers

Python comes with a debugger pdb. To stop the script at a given point in the code, put the following

import pdb; pdb.set_trace()

emacs, pdb, gud.el ( : "python-mode" pdb, @Andreas Röhler ). pdb name_of_script.py, emacs, C-x SPACE , . menu-bar , (GUD). pdb *gud-pdb*, emacs.

+2

?

import ipdb; ipdb.set_trace()

- script python script.py.

ipython (ipython - python):

pip install ipdb

edit: , M-x pdb RET pdb myscript.py RET, pdb, emacs , , ipdb.set_trace()?

Env?

envs, . virtualenvwrapper ELPA M-x venv-workon.

+6

All Articles