when used within an if/else fails

Steven D'Aprano steve+comp.lang.python at
Wed Nov 28 21:50:07 CET 2012

On Wed, 28 Nov 2012 11:39:48 -0800, Kevin T wrote:

> with other languages i always expand tabs to spaces.  the vi plugin does
> do this properly.  if i change all indents to be spaces only will python
> behave?  i inherited a good deal of the code that i am using, which is
> tab based.

Python will behave correctly if you use all spaces, or all tabs, for 
indents. If you mix spaces and tabs, anything can happen.

For this reason, Python 3 is more strict and will raise an explicit error 
when it detects mixed spaces/tabs in an indent.

See also the tabnanny tool provided with Python:

[steve at ando ~]$ python -m tabnanny
Usage: /usr/local/lib/python2.7/ [-v] file_or_directory ...


More information about the Python-list mailing list