0

The l command for pdb is documented like so:

l: List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing.

I often use this command (in ipdb as well) to see where I am, then run a few other commands to diagnose the error which will fill my terminal with other output, then want to see the code around the error again. Since a repeated l continues previous listing, this doesn't help me.

How do I opt to not continue the previous listing upon repeated call, and instead list code around the error/current line again?

There are options to manually supply start and stop line numbers for the listing, but that is too cumbersome and messes up the flow of debugging.

ll is often useful, but sometimes the current scope is too long, which means the error will be off screen anyways.

My current workaround is to change scope and change back using up and down commands, which is a bit clunkier than I'd want.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Anton
  • 365
  • 2
  • 12
  • 1
    I don't have any familiarity with `pdb` so I can't be sure; but does https://stackoverflow.com/questions/5169702 answer your question? – Karl Knechtel Sep 02 '23 at 14:21
  • Almost! Turns out that pdb got the addition of 'l.' for that in Python 3.2 https://github.com/python/cpython/issues/48429 , but for some reason that doesn't work in ipdb for me. Another suggested solution automates my current workaround. Haven't found out why ipdb doesn't have 'l.' yet. It is supposed to provide the same functionality as pdb, but with various improvements. The 'l.' is not documented in the pdb docs, perhaps that is why ipdb hasn't also picked it up. Well Googled though, thank you! – Anton Sep 02 '23 at 17:26
  • Ha! Found out! Turns out the missing 'l.' was fixed in ipython 8.15 https://github.com/gotcha/ipdb/issues/203 https://github.com/ipython/ipython/pull/14121 https://ipython.readthedocs.io/en/stable/whatsnew/version8.html#ipython-8-15 , released yesterday 2023-09-01. Just needed update ipython and now it works. Impeccable timing! – Anton Sep 02 '23 at 17:52

0 Answers0