Question

Would someone please point me to a discussion or documentation on the 'unindent' error in Python. I am using ipython notebook, 2.7 python. The right arrow test (to locate spaces and tabs) is not a good test for the notebook as every right arrow moves just one space even where I used tabs as in a def definition. I would really like to know exactly what causes these errors. Thanks Ron

Was it helpful?

Solution

Do not mix spaces and tabs. PEP8 says to use spaces. Convert your tabs to 4 spaces (again, from PEP8). Here is a decent discussion on the thoughts behind spaces vs tabs.

Therefore, it is generally a good idea not to mix tabs and spaces for indentation. If you use tabs only or spaces only, you're fine.

Furthermore, it can be a good idea to avoid tabs alltogether, because the semantics of tabs are not very well-defined in the computer world, and they can be displayed completely differently on different types of systems and editors. Also, tabs often get destroyed or wrongly converted during copy&paste operations, or when a piece of source code is inserted into a web page or other kind of markup code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top