your favorite debugging tool?

E

Esmail

Hi all,

What is your favorite tool to help you debug your
code? I've been getting along with 'print' statements
but that is getting old and somewhat cumbersome.

I'm primarily interested in utilities for Linux (but
if you have recommendations for Windows, I'll take
them too :)

I use emacs as my primary development environment, FWIW.
Someone mentioned winpdb .. anyone have experience/comments
on this? Others?

Thanks,
Esmail
 
A

Aahz

What is your favorite tool to help you debug your code? I've been
getting along with 'print' statements but that is getting old and
somewhat cumbersome.

Despite the fact that I've been using Python for more than a decade,
print is still my mainstay (or possibly logging to a file).
 
H

Hendrik van Rooyen

Despite the fact that I've been using Python for more than a decade,
print is still my mainstay (or possibly logging to a file).

Same here, although I have not been abusing python for as long as Aahz has
been using it.

I find that python pretty much does more or less what I expect it to, and
where it does not, a print quickly gets me to RTFM when I have been rolling
along under intuition.

And the final arbiter is of course the interactive prompt.

- Hendrik
 
F

Francesco Bochicchio

Hi all,

What is your favorite tool to help you debug your
code? I've been getting along with 'print' statements
but that is getting old and somewhat cumbersome.

I'm primarily interested in utilities for Linux (but
if you have recommendations for Windows, I'll take
them too :)

I use emacs as my primary development environment, FWIW.
Someone mentioned winpdb .. anyone have experience/comments
on this? Others?

Thanks,
Esmail

Although like the others I mostly use print statements, in a few
occasions I have found useful to resort to a full-blown debugger. Of
the ones I have used, the one provided by eclipse+pydev is the one I
liked most. The one in pywin32 IDE is basic but can be useful.
With emacs, one should be able to use pydb, but I never used that,
although emacs is my most used programming environment on most
platforms.

About print cumbersomeness, I agree. As I posted elsewhere, I'd like a
'trace mechanism' with the
following characteristics:
1. Can be enabled/disabled easily, and when it is dsabled it has no
runtime costs ( i.e. disabled 'trace' statements do not generate any
code)
2. Can be enabled/disabled on a class/function/method base (e.g.
enable only the trace in a method ), to only get the trace output from
the code you are debugging
3. Make it easy to report the context (i.e. generate messages which
starts with 'class.method:', without
hanving to hardcode class name and method name).

I know about the 'trace' and 'logging' modules, but neither seem to
satisfy the above requirements. Probably using python introspection
and metaprogramming features it is possible to do somethinmg that
covers at least 2 and 3. Not sure about one (using if __debug__ you
can reduce the runtime cost when
compiling in optimized mode, but probably not nullify it).

Ciao
 
P

Paul Rubin

Esmail said:
What is your favorite tool to help you debug your
code? I've been getting along with 'print' statements
but that is getting old and somewhat cumbersome.

Beyond print statements, I use pdb a lot. Winpdb (www.winpdb.org) is
even better, but is kind of cumbersome to get working.
 
R

Robert Marshall

Beyond print statements, I use pdb a lot. Winpdb (www.winpdb.org) is
even better, but is kind of cumbersome to get working.

And you can run it (pdb) within emacs - though I find a little roughness
in working out the exact interactions keeps ending up (ie the source
buffer displayed) in the wrong stack frame - afaict

Robert
 
M

Michele Simionato

Hi all,

What is your favorite tool to help you debug your
code?

The times when I would just use 'print' are long past. Nowadays I
spend lots of my time
with code written by others than myself. I use pdb all the time, and
now also ipdb
(ipdb is very cool if you are used to ipython).

M.S.
 
E

Esmail

Paul said:
Beyond print statements, I use pdb a lot. Winpdb (www.winpdb.org) is
even better, but is kind of cumbersome to get working.

Hi,

2 quick questions.

Re pdb, if you have a 'pointer' (ie reference) to an object, is there
an easy way to dump out its contents, ie all of its members short of
writing a method that does that and then calling it?

Anyone know what is going on with the winpdb site? I haven't been able to
get to it in the last few days.

Thanks,
Esmail
 
E

Esmail

Robert said:
And you can run it (pdb) within emacs - though I find a little roughness
in working out the exact interactions keeps ending up (ie the source
buffer displayed) in the wrong stack frame - afaict

Thanks Robert, I'll have to give that a try.

Esmail
 
E

Esmail

Michele said:
The times when I would just use 'print' are long past. Nowadays I
spend lots of my time
with code written by others than myself. I use pdb all the time, and
now also ipdb
(ipdb is very cool if you are used to ipython).

Never heard of ipdb, I'll have to check it out.

Thanks,
Esmail
 
E

Esmail

Hi Ben,

Ben said:
Whenever a simple output statement is too cumbersome for debugging, I
take it as a sign that the program is too cumbersome to follow.

I'll have to think about this .. though my gut says this is true :)

re your other point about the interactive shell, I agree it's useful, but
to me still doesn't quite do what a full-fledged debugger can - but perhaps
that is a reflection of my skill with the shell at this point.

Always more to learn.

Esmail
 
J

Jean-Michel Pichavant

Esmail said:
Hi Ben,



I'll have to think about this .. though my gut says this is true :)
That is not always true. When it comes to implement complex tasks, you
can't always avoid writing complex code. Python does not get your code
more complex than your algorithm, but it cannot always simplify it.

Ben is right when he says that code can often be written in a more
simpler manner, but they are some occasions when you have to write
complex code, that the print debug statement won't be efficient enough
to sort things out. I personally develop/maintain a full application
written in python (and quite complex for some parts), using the ipdb
debugger just saved my hours (days) of headache about some very
difficult bug to spot
re your other point about the interactive shell, I agree it's useful, but
to me still doesn't quite do what a full-fledged debugger can - but
perhaps
that is a reflection of my skill with the shell at this point.

Always more to learn.

Esmail

90% of the time, print statements + ipython shell will do the trick. The
post mortem debugging is also very useful. Execute your python file in
ipython, then when it exits upon exception, executeYou can then inspect the symbols easily.

JM
 
F

Falcolas

Same here, although I have not been abusing python for as long as Aahz has
been using it.

...

And the final arbiter is of course the interactive prompt.

- Hendrik

The only thing I would add to these comments is the fact that writing
helper functions for using print with complicated routines is very
simple, though perhaps not obvious. For example, consider the
following for unrolling list comprehensions or generators without
having to re-write them:

def trace(iterable):
for x in iterable:
print x
yield x

~G
 
R

Robert Kern

Note that it's only a sign, *not* an ironclad guarantee. But it's the
right way to bet, IME.


This, on the other hand, I find even more consistent: if the code can't
be effectively inspected from the interactive interpreter, that's a sure
sign that its external interfaces are poor or its internal dependencies
too tightly coupled; or more likely both.

And a debugger is a great tool to help you figure out exactly why your code
doesn't actually have the wonderful decoupling that you thought you designed
into it so you can fix it. :)

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
R

Robert Kern

Never heard of ipdb, I'll have to check it out.

It's not really a separate thing, just the pdb integration into the IPython
interactive shell (which I highly recommend that you check out).

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
E

Esmail

Ben said:
Note that it's only a sign, *not* an ironclad guarantee. But it's the
right way to bet, IME.

:) .. I took it as a rule of thumb too .. I didn't meant to imply
anything more serious. These design guidelines help though.

Thanks,
Esmail
 
M

Marius Gedminas

Re pdb, if you have a 'pointer' (ie reference) to an object, is there
an easy way to dump out its contents, ie all of its members short of
writing a method that does that and then calling it?

Usually

pp vars(your_object)

does what you want
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top