0

I get this error when I run my python program "sometimes" <string>:8: (ERROR/3) Unexpected indentation.

I don't see any obvious negative effects from it I have a large program with lots of dependencies and lots of source files. Because it occurs sometimes I am unable to pinpoint what change I made introduced this messsage.

What tool or technique can I use to identify the file or files that are responsible for this error? I am not even sure what is.

Jim
  • 2,034
  • 2
  • 15
  • 29
  • Replace tabs for spaces - it's the recommended thing to do since [PEP8](https://stackoverflow.com/questions/120926/why-does-python-pep-8-strongly-recommend-spaces-over-tabs-for-indentation) – Aviv Yaniv Aug 25 '20 at 13:07
  • 1
    Most of the time, this is caused by mixing tabs and spaces as the method of indentation. Run a program to detect. – dawg Aug 25 '20 at 13:08
  • For starters: an IDE / Editor that displays spaces and tabs inline to check if you mixed them. Also use 4 spaces to indent 1 level so its more obvious where you misindented. then check all places where you end a line on a : (if / while / for / with / ...) and if you indented afterwards, then every line in a block thats more indented then the others without need to be more indented – Patrick Artner Aug 25 '20 at 13:08
  • Too many files to automatically replace tags for spaces without fear of breaking the system – Jim Aug 25 '20 at 13:08
  • It likely has to do with the number of tabs or spaces at the start of the lines. If the traceback does not help, cut some big blocks out, run it again, until you find out which block is the culprit. You say it only happens sometimes - I assume the program is taking different paths? Or does it happen only sometimes without you cahnging anything? – lucidbrot Aug 25 '20 at 13:09
  • The goal of the question was how to find it. Globally reformatting a large projects is just not an option, which is why the existing question didnt really help. – Jim Aug 25 '20 at 13:12
  • How do I get the traceback? I am not the one printing the error! A traceback would be amazing – Jim Aug 25 '20 at 13:12

0 Answers0