IndentationError: two many levels of indentation

Erik Max Francis max at alcyone.com
Fri Mar 7 03:50:12 EST 2003


"Martin v. Löwis" wrote:

> There is no limit in the compiler that I know of. Instead,
> IndentationError indicates a genuine error in your Python code. It is,
> for example, generated if you write
> 
>    print x
>       print y
> 
> This is a IndentationError (which is a SyntaxError), as you shall not
> indent the second line more than the first one.

It would indeed appear there's some sort of limit.  I did the following:

>>> output = file('indent.py', 'w')
>>> for i in range(500):
...  print >> output, ' ' * i + "if 1:"
... 
>>> print >> output, ' ' * i + "pass"
>>> output.close()

and then ran the script and got:

max at oxygen:~/tmp% python indent.py 
  File "indent.py", line 101
    if 1:
        ^
IndentationError: too many levels of indentation

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ No one should have to dance backward all their lives.
\__/ Jill Ruckelshaus
    Bosskey.net: Counter-Strike / http://www.bosskey.net/cs/
 A personal guide to Counter-Strike.




More information about the Python-list mailing list