7
My first Python script crashed hard after 2 hours of work
Last Tuesday I spent 2 hours writing a script to sort my music files and it gave me a bunch of errors I didn't understand. Turns out I forgot to close a bracket and used a wrong variable name in three places. Any tips on catching these simple mistakes faster before I waste another afternoon?
2 comments
Log in to join the discussion
Log In2 Comments
johnson.lee2d ago
Wait, 2 hours with no test runs? Even a quick syntax check would've caught the bracket.
6
amygonzalez2d ago
Wait, you spent 2 hours on a script and didn't test it one time? That's wild. I always run my code after every 3-4 lines just to make sure it's not broken. Saves you from that sinking feeling when you hit run and get 50 errors at once.
For catching brackets and variable name typos, use an editor with linting. VS Code or even Notepad++ will highlight a missing bracket in red before you even run it. Also, if you reuse a variable, just double check the spelling three times before typing it out.
Practice the "save and run early" habit. Even if your script is only half done, run it. If it works, great. If not, you only have a few lines to debug instead of two hours worth of mess.
5