8
Finally nailed down why my 'if' statements kept breaking - it was a spacing thing the whole time
I spent like 3 hours last night trying to figure out why my Python script kept erroring out on line 12. Turned out I was mixing tabs and spaces in the indentation, something every tutorial warned about but I thought I had under control. I counted and there were 7 tabs mixed into a block that needed all spaces. It's a dumb beginner mistake but I see people in the help threads making it all the time, usually because their editor is set to insert tabs but they're copying example code that uses spaces. Does anyone else have a specific little rule they check first when code won't run, or is it always the indentation?
2 comments
Log in to join the discussion
Log In2 Comments
the_vera2d ago
idk about always being indentation, but that's definitely my go-to when Python specifically acts up. I've been there with the tab vs space thing, it's the worst because your editor lies to you and makes it look fine. My personal rule now is to just hit space four times manually every time, no tab key at all, even if it's slower. Another thing I check right after is mismatched quotes or brackets, especially if I've been editing a long string and closed something wrong.
10
stella_roberts2d ago
Yeah but have you ever had a bug because of a forgotten comma in a list? That one got me good.
9