3
I finally found a way to debug Python without losing my mind
I kept getting these weird errors in my code and spending hours staring at it. Then I started using print statements with specific markers like 'step 1 done' and 'step 2 done' to see where it breaks. It sounds dumb but it helped me find a bug in a loop that was running 500 times in under 10 minutes. Has anyone else tried this or is there a better way for beginners?
4 comments
Log in to join the discussion
Log In4 Comments
jason_stone593d agoMost Upvoted
Oh man, I gotta push back on this one a bit. Print debugging is fine for tiny scripts but it'll drive you crazy once your code gets bigger (and you'll end up deleting all those print statements later anyway).
9
torres.blair3d ago
Print debugging isn't that serious honestly. Like yeah you delete them later but who cares? The time you waste setting up a proper debugger for a tiny script is way more annoying than just throwing a few print statements in and moving on. Most people's code isn't some huge complex thing anyway, it's just a quick script to get a job done. And honestly even for bigger stuff I've seen people rely on print statements just fine, they just comment them out or add a flag. Not everything needs to be this big production with breakpoints and watch windows. Sometimes simple works and overthinking it is the real waste of time.
4
the_claire3d ago
Oh man, I feel this SO much because I once spent three hours debugging a script only to realize I was printing the wrong variable name the whole time. Print debugging is basically me yelling at my own code in real time and hoping it yells back with something useful. Honestly at this point I'm just impressed whenever my computer doesn't burst into flames from all the "print('here')" statements I've littered everywhere.
7
ruby6593d ago
Did you ever figure out why it was looping 500 times in the first place? That sounds like a headache, glad you found it quick.
5