Skip to content
Advertisement

How can I make ipdb show more lines of context while debugging?

By default, during debugging in IPython, ipdb shows one line above and one line below the current position in code.

Is there an easy way to make the area shown a bit bigger? I’d think it would be configurable, but haven’t been able to find it.

Advertisement

Answer

easy way to do this – 2022

  • figure out where you’re loading ipdb from
  • import ipdb
  • print(ipdb.__file__)
  • open __main__.py from that folder
  • search for except (configparser.NoSectionError, configparser.NoOptionError):
  • below it is 3. Change that to your desired value

Why this is better than the proper way:

  • I don’t need to learn a new configuration language
  • I don’t need to create a new configfile
  • I don’t need to debug why my configfile isn’t being picked up
  • you never get tricked by file scoping/permissions/visibility since you are sure which ipdb module is being loaded (i.e. it covers virtualenvs too)
  • I don’t have to talk to upstream and try to convince them to adopt this default.
Advertisement