How to debug python code?

Discussion in 'Python' started by sushant.sirsikar@gmail.com, Mar 31, 2006.

  1. Guest

    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
    , Mar 31, 2006
    #1
    1. Advertising

  2. Guest

    , Mar 31, 2006
    #2
    1. Advertising

  3. 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/> <
    Dennis Lee Bieber, Mar 31, 2006
    #3
  4. 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('@')])"
    bruno at modulix, Mar 31, 2006
    #4
  5. Ravi Teja Guest

    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.
    Ravi Teja, Mar 31, 2006
    #5
  6. Kent Johnson Guest

    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
    Kent Johnson, Mar 31, 2006
    #6
  7. 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:
    Thomas Guettler, Mar 31, 2006
    #7
  8. 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
    Grant Edwards, Mar 31, 2006
    #8
  9. R. Bernstein Guest

    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.
    R. Bernstein, Mar 31, 2006
    #9
  10. R. Bernstein Guest

    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.
    R. Bernstein, Mar 31, 2006
    #10
  11. Guest

    wrote:
    > 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


    If you are having issues you also might want to try:
    http://pychecker.sourceforge.net/
    and see if it finds your problem. You might get lucky.

    Or just make the bigger install:
    http://stani.be/python/spe/blog/
    that one already includes pychecker and a python debugger.

    Sorry for the noise if you were just looking for instructions for pdb.
    , Mar 31, 2006
    #11
  12. Johannes Nix Guest

    Dennis Lee Bieber <> writes:

    > 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).



    I think the advantage of this method is that one has to become
    clear what the state of the program should look like.

    For the same reason, unit tests may help to develop a
    proper specification of the task of a module.

    However, pdb's port mortem debugging can be helpful when a
    program takes a lot of time to hit the error, and
    a large amount of data is in play, for example for
    numerical computations.

    Johannes
    Johannes Nix, Apr 3, 2006
    #12
  13. Guest

    I don't have an example, but what I do is insert:

    import pdb
    pdb.set_trace()

    before the code that I think is causing the problem
    (or that the traceback barfed at).

    Then hit 'l' (lowercase L) to get a list of the code
    which is being executed.

    Use 'p' to look at variables. eg p some_local

    Use 'n' to execute the current line of code
    (doesn't follow method or function calls)

    Use 's' to step through code, including following
    function and method calls.

    Finally, 'c' to continue execution as normal.

    There are other options, but that should get you started.
    And look at the article linked elsewhere in this thread.

    pdb - because fencing off Alaska is too damn slow, binary
    search or not.

    jtm
    , Apr 4, 2006
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RonL
    Replies:
    0
    Views:
    728
  2. jin zhang
    Replies:
    1
    Views:
    1,200
    Chris Uppal
    Oct 2, 2004
  3. ringos75
    Replies:
    0
    Views:
    938
    ringos75
    Apr 14, 2005
  4. Mike C. Fletcher
    Replies:
    3
    Views:
    968
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Oct 12, 2003
  5. André
    Replies:
    3
    Views:
    1,558
Loading...

Share This Page