views:

166

answers:

6

I'm looking for a debugging tool that will run my Python app, but display which line is currently being processed -- like an automatically stepping debugger. Basically I want to see what is going on, but be able to jump in if a traceback occurs.

Any suggestions?

A: 

The integrated debugger in Wing IDE is quite versatile and nice to work with. (The Wing IDE 101 version is freeware.)

Amber
+1  A: 

I think you're looking for the pdb module.

Zach Hirsch
+3  A: 

Winpdb is a good python debugger. It is written in Python under the GPL, so adding the automatic stepping functionality you want should not be too complicated.

Luper Rouch
+1 for winpdb if you want to watch what's going on. Don't be misled by the name: it's not (just) a Windows app.
Daniel Roseman
@Daniel: Thanks, the name is very misleading and I won't never have tried it without your commend.
dalloliogm
+1  A: 

"Basically I want to see what is going on, but be able to jump in if a traceback occurs."

Here's a radical thought: Don't.

"Watching" is a crutch. You should be writing small sections of code that you know will work. Then put those together.

Watching sometimes results from "I'm not sure what Python's really doing", so there's an urge to "watch" execution and see what's happening. Other times watching results from writing a script that's too big and complex without proper decomposition. Sometimes watching results from having a detailed specification which was translated into Python without a deep understanding. I've seen people doing these; of course, there are lots more reasons.

The advice, however, is the same for all:

  1. Break things into small pieces, usually classes of functions. Make them simple enough that you can actually understand what Python is doing.

  2. Knit them together to create your larger application from pieces you actually understand.

Watching will limit your ability to actually write working software. It will -- in a very real way -- limit you to trivial programming exercises. It's not a good learning tool; and it's a perfectly awful way to create production code.

Bottom Line.

Don't pursue "watching". Decompose into smaller pieces so you don't need to watch.

S.Lott
I disagree with this. There are times when you don't know what you are doing. You don't understand why it isn't working. The output you get is not what you expected, and it's not failing where you think. Debuggers exist for a reason.
Christopher
I agree with S. Lott. Many times what people use a debugger for could be accomplished by test driven development.
anio
@Christopher. I understand that it's frustrating when things don't make sense. Debugging isn't the best way to "understand". The best way is to hypothesize, experiment, and confirm or reject the hypothesis. Good software works because it's written so it absolutely must work. Bad software works because stepping through the debugger and adding random statements eventually got it to appear to work.
S.Lott
A: 

There is also a very nice debugger in The Python Eclipse plugin.

Christopher
A: 

Try IPython alongwith ipdb

sharjeel