4

I'm trying to become more adept at using the debugger, and am following the examples given in http://www.onlamp.com/pub/a/python/2005/09/01/debugger.html. I'm currently trying this script:

#!/usr/bin/env python

import ipdb

def test_debugger(some_int):
    print "start some int>>", some_int
    return_int = 10 / some_int
    print "end some_int>>", some_int
    return return_int

if __name__ == "__main__":
    ipdb.run("test_debugger(0)")

However, if I run it and try to press n, I get a NameError:

> <string>(1)<module>()

ipdb> n
NameError: "name 'test_debugger' is not defined"

As I understand from https://docs.python.org/2/library/pdb.html#pdb.run, it should be possible to use the n(ext) command to run until the actual bug. Can someone explain what is going on here?

1
  • 1
    is there a difference between pdb and ipdb? Commented Feb 14, 2017 at 12:44

1 Answer 1

2

From the docs you mention, the explanation links to https://docs.python.org/2/library/functions.html#eval.

It seems that your call to ipdb.run() does not provide a globals or locals dict, so test_debugger is not defined in the context of run.

You can make it work like this:

ipdb.run("test_debugger(0)", {'test_debugger': test_debugger})

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.