1. 7
  1.  

  2. 4

    import ipdb; ipdb.set_trace() (if you can’t install packages, use pdb instead of ipdb. It’s built in).

    1. 4

      breakpoint()

    2. 3

      It’s also worth mentioning that when you’re in the debugger (at least with pdb), then calling the pp command provides automatic pretty-printing through the pprint module without having to import it specifically. This is something I only found out about recently and while it’s definitely not as wide-ranging as Rich’s, it’s still very handy in my eyes.

      1. 1

        👀 Thanks ! I always complained about pdb without actually thinking about reading its documentation. I also just learned about ll or retval and I am definitely trying it today !

      2. 1

        Years ago I made a plugin for Sublime Text for doing some basic formatting of data structures you might print using print(). It’s nice not having to import extra things in order to get readable formatting and sometimes you might get big Python dicts outputted in log lines already which could like to read more easily.

        The plugin works well enough for me to use it regularly, but it could do with better handling of stuff like datetime.datetime objects, as they currently get split over many lines. I just never spend the time on sorting it out so it handles cases like that better.

        1. 1

          Thanks for the tips, Icecream looks useful !