4

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?

1 Answer 1

2
+50

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.

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

1 Comment

Didn't have the time to check this yet, but since bounty is expiring I'll award it anyway, hoping it will be deserved.

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.