A junior at my office sent me a 40 line Python script
last night. It wouldn't run. The error said IndentationError, unindent does not
match any outer indentation level. Line 27. I opened the file and
stared at line 27 for 20 minutes. It looked perfect. Same spacing
as the line above, same spacing as the line below. I felt stupid.
I've written Python for years, and I know the usual suspects. Missing colon, wrong
block, bad copy paste. I checked all three. Then I deleted the line and
typed it again by hand. Same error. The junior said, sir, I only copied
it from a tutorial site and fixed 2 lines myself. That's the part I
keep thinking about. He didn't type that whole block himself, and neither did I.
At 11pm I gave up and went to sleep, which is never a
good sign. This morning I opened the file in a different editor and the
error was still sitting there. Everything lined up on screen, but the file
clearly disagrees with my eyes, and the file wins. I don't want to just
say it's probably tabs and send him away. I want to understand it properly.
So here's my question for people who've been through this. How do you
find the bad character? Do you turn on visible whitespace, or run some check
that points straight at the bad line? And can one single line break a
whole file if the rest of it looks completely fine? I'd like to give
him a proper method he can reuse, not a guess. He's 22 and keen.
💻techbhai
Tech Member
Sharing programming, web dev, and hardware tips on Hyd.Circle.