Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Python - How to debug python code?

 
Thread Tools Search this Thread
Old 03-31-2006, 05:18 AM   #1
Default How to debug python code?


hi,
I am new to Python programming.I am not getting exactly pdb.Can
anyone tell me effective way to debug python code?
Please give me any example.
Looking for responce.
Thank You.
Sushant



sushant.sirsikar@gmail.com
  Reply With Quote
Old 03-31-2006, 05:53 AM   #2
ravi.annaswamy@gmail.com
 
Posts: n/a
Default Re: How to debug python code?

Here is an outstandingly well written article, with examples, from
Stephen Ferg:

http://www.ferg.org/papers/debugging_in_python.html

Ravi

  Reply With Quote
Old 03-31-2006, 07:17 AM   #3
Dennis Lee Bieber
 
Posts: n/a
Default Re: How to debug python code?

On 30 Mar 2006 21:18:50 -0800, declaimed the
following in comp.lang.python:

> hi,
> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?


I think I toyed with pdb back around 1993... Never needed it...

Of course, with so many different languages and debuggers in my
life, I've never found time to master any but the old VMS debugger
(which is nothing more than a very complex error handler <G>)

My typical debugging technique is the infamous "wolf fence" (there's
one wolf in Alaska, how do you find it? First build a fence down the
middle of the state, wait for the wolf to howl, determine which side of
the fence it is on. Repeat process on that side only, until you get to
the point where you can see the wolf). In other words; put in a few
"print" statements until you find the statement that is failing (then
maybe work backwords from the "tracks" to find out where the wolf/bug
comes from).
--
> ================================================== ============ <
> | Wulfraed Dennis Lee Bieber KD6MOG <
> | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

  Reply With Quote
Old 03-31-2006, 08:11 AM   #4
bruno at modulix
 
Posts: n/a
Default Re: How to debug python code?

wrote:
> hi,
> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?


(automated) unit tests + print statements + the interactive shell are
usually enough. I almost never used pdb in 5+ years of Python programming.

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in ''.split('@')])"
  Reply With Quote
Old 03-31-2006, 09:36 AM   #5
Ravi Teja
 
Posts: n/a
Default Re: How to debug python code?

1.) Print statements
2.) IDEs

Most Python IDEs provide visual debuggers so that you don't have to use
command line ones such as pdb.

As with all languages that allow to be executated as a script as well,
print statements usually get the job done quite well in most cases.

Please read the Python FAQ (as you should for any new language you
learn) in its entirety.
http://www.python.org/doc/faq/
It answers your IDE question you posted in the other thread as well as
many of your future questions quite well.

  Reply With Quote
Old 03-31-2006, 10:48 AM   #6
Kent Johnson
 
Posts: n/a
Default Re: How to debug python code?

wrote:
> hi,
> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?


I too rely mostly on unit tests and print statements for debugging, but
occasionally I use winpdb which is a pretty nice GUI debugger.
http://www.digitalpeers.com/pythondebugger/

Kent
  Reply With Quote
Old 03-31-2006, 01:50 PM   #7
Thomas Guettler
 
Posts: n/a
Default Re: How to debug python code?

Am Thu, 30 Mar 2006 21:18:50 -0800 schrieb sushant.sirsikar:
> hi,
> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?


Hi,

I try to debug the code while I type: Use "assert".

Then if you get an AssertionError you can insert print statements or
raise("var=%s var2=%s" % (var, var2))
to narrow down the problem. I never used pdb.

HTH,
Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher:

  Reply With Quote
Old 03-31-2006, 03:30 PM   #8
Grant Edwards
 
Posts: n/a
Default Re: How to debug python code?

On 2006-03-31, <> wrote:

> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?


1) Read your code. Think.

2) Add some "print" statements.

3) goto 1)

--
Grant Edwards grante Yow! Where's th' DAFFY
at DUCK EXHIBIT??
visi.com
  Reply With Quote
Old 03-31-2006, 04:05 PM   #9
R. Bernstein
 
Posts: n/a
Default Re: How to debug python code?

writes:

> hi,
> I am new to Python programming.I am not getting exactly pdb.Can
> anyone tell me effective way to debug python code?
> Please give me any example.
> Looking for responce.
> Thank You.
> Sushant


Well, I guess (in addition to the other good suggestions in this
thread) this is an obvious place to plug pydb
http://bashdb.sourceforge.net/pydb

If you are using pdb, I think you'll find pydb, um, better.
  Reply With Quote
Old 03-31-2006, 04:08 PM   #10
R. Bernstein
 
Posts: n/a
Default Re: How to debug python code?

Dennis Lee Bieber <> writes:

> On 30 Mar 2006 21:18:50 -0800, declaimed the
> following in comp.lang.python:
>
> > hi,
> > I am new to Python programming.I am not getting exactly pdb.Can
> > anyone tell me effective way to debug python code?

>
> I think I toyed with pdb back around 1993... Never needed it...
>
> Of course, with so many different languages and debuggers in my
> life, I've never found time to master any but the old VMS debugger
> (which is nothing more than a very complex error handler <G>)


That's one reason why in my bash and GNU make debugger (and in
extending pdb), I've stuck to the gdb command set: the effort that is
spent mastering gdb can be transfered in the GNU Make, Bash, *AND*
Python debuggers.
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump