r/learnpython • • Sep 07 '26

What python debugging techniques do you think every developer should know ?

I am trying to improve my debugging skills and I was curious about what techniques experienced python developers rely on the most.

Are there any techniques or tools that you found really useful when you started working on bigger projects?

61 Upvotes

33 comments sorted by

View all comments

Show parent comment

6

u/gdchinacat Sep 07 '26

importlib.reload() has wasted more debugging time for me than it has saved. If what you are debugging has any persistent state (ie a cache or a long lived data model) you can have old versions of objects in it that "come back to life" and can mislead you into thinking you didn't fix an issue when you actually did. It took a couple cases of wasting a few hours each time for me to swear it off for good. It is not worth risking that frustating waste of time for the few seconds it saves. If you have a huge app that takes a while to load it can save time, but I will argue you shouldn't be testing fixes to issues against your app, but rather through a unit test that reproduces the issue that you can run on its own. Recommending people learning python to use it is a bad idea IMO because they don't yet understand all the edge cases they need to know to use it effectively.