Issue
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?
Solution
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})
Answered By - Laurent S
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.