[Tutor] Loop-checking question
kent37 at tds.net
Sat May 12 19:37:42 CEST 2007
Alan Gilfoy wrote:
> My programs often have long, detailed loops in them, and would like
> to, as I'm executing the loop, view what part of the loop Python is
> currently processing.
> Thus, if my program gets stuck in one part of the loop, I would see that.
> Thus, if one part of my loop is never triggered, I would see that.
> I could use, within my loop, print 'I am here, at part X of the loop',
> but I believe that would be far to clunky to put in every section of
> my program's loop(s).
I'm not really sure what you expect this view to look like. I don't know
of any tool that will let you dynamically watch a program as it
executes. Some alternatives:
- A debugger lets you step through the code and see how it behaves.
winpdb is a pretty nice GUI-based Python debugger and some Python
development tools have built-in debuggers.
- If the program is stuck in a loop, pressing control-C will abort the
loop and give a stack trace showing you where it was.
- The Python profiler will tell you (after the fact) how much time you
spend in each function. To see what part of a loop the program is in you
would have to break the loop up into functions.
- A code coverage tool will tell you (after the fact) which lines of the
program were executed and which were not. (google python code coverage)
More information about the Tutor