Reputation: 11863
Apparently I've unlearned how to debug with python.
I run bpython3 -i myfile.py
, but when an exception occurs I still don't have access to the program variables, nor I can find any command like gdb
's up
and down
.
I've tried to import pdb
and play around with it, but I didn't manage to obtain much. And it definitely isn't integrated into bpython in any way.
As far as I remember, it was pretty straightforward, like gdb
, but apparently I remember uncorrectly and now I'm clueless. Information online about python debuggers is confused, vague, and I couldn't find anything similar to what I was using before, so I came to ask here: am I missing something obvious?
Upvotes: 4
Views: 337
Reputation: 287755
bpython3
is just an interface for an interactive Python shell. For gdb-like debugging, use pdb, which supports gdb-like commands:
$ python3 -m pdb t.py
> /tmp/t.py(2)<module>()
-> def a():
(Pdb) c
Traceback (most recent call last):
File "/usr/lib/python3.2/pdb.py", line 1556, in main
pdb._runscript(mainpyfile)
File "/usr/lib/python3.2/pdb.py", line 1437, in _runscript
self.run(statement)
File "/usr/lib/python3.2/bdb.py", line 405, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "/tmp/t.py", line 2, in <module>
def a():
File "/tmp/t.py", line 4, in a
b()
File "/tmp/t.py", line 7, in b
1/0
ZeroDivisionError: division by zero
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /tmp/t.py(7)b()
-> 1/0
(Pdb) up
> /tmp/t.py(4)a()
-> b()
(Pdb) print x
1
If you want to use bpython(3) as your debugger, you'll have to include some glue code.
Upvotes: 2