[Python-ideas] Interactive trace function
Jacob Holm
jh at improva.dk
Fri Mar 20 15:26:23 CET 2009
Gerald Britton wrote:
> Years ago I worked for a while in REXX. It was a fairly advanced
> scripting language for its time and we used it on some substantial
> mainframe projects. One thing that I liked and miss in Python is the
> "trace" statement.
>
> Basically, you could insert a "trace" statement in a REXX program and
> then, when you ran it, it would step through the program a line at a
> time. This gave you the chance to follow your code through tricky
> sections and display variables after each step. I know it saved me
> hours of troubleshooting of tricky problems.
>
> I would like to know if anyone has ever proposed something similar for
> Python. It would work something like this:
>
> 1. In an interactive session, you could issue a trace command.
> Thereafter, whatever you ran would be done a step at a time, with a
> terminal prompt after every statement for you to print anything you
> like that would help you understand the state of the program at that
> point.
>
> 2. From the command line, you could add a --trace option, or something
> like it, to ask Python to launch the program interactively with trace
> enabled, which would work as described above.
>
> 3. If you have a problematic piece of code, you could insert a trace
> statement just before the troubled section. Then when you ran the
> program, when it came to the trace statement, it would begin an
> interactive trace at that point as described above. (You would have to
> start your program from the command line for this to make sense.)
>
> Has something like this ever come up before? Is there a way to do this today?
>
>
>
How about:
import pdb; pdb.set_trace()
I use that for debugging all the time...
- Jacob
More information about the Python-ideas
mailing list