spaces on idles last line

Anton Vredegoor anton at vredegoor.doge.nl
Tue Jul 29 20:29:43 EDT 2003


If editing a script with another editor than Idle (f.e. Scite)
sometimes there are spaces left on the last line. If such a script is
run from the Scite command line with f.e. "pythonw -u idlespace1.py"
the script runs fine. However if next the script is run from Idle,
there is the following error:

Python 2.3b1 (#40, Apr 25 2003, 19:06:24) [MSC v.1200 32 bit (Intel)]
on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> 
IndentationError: unindent does not match any outer indentation level
(idlespace1.py, line 6)

the script:
<start script>
def test():
    print "hi"

if __name__=='__main__':
    test()
   <end script>

Note that there is no empty last line in this script: the last line
contains spaces.

A syntaxerror is also possible:

>>> 
  File "xxxx\xxxx\idlespace2.py", line 2
    
    ^
SyntaxError: invalid syntax

The script that caused the error above:
<start script)
print "hi"
 <end script>

Saving a script with Idle repairs it immediately, because Idle
automagically adds an empty last line, however a "check module" from
Idle's menu doesn't detect the error. This made it difficult to even
write a script to find out what caused it. 

Is there a reason for Idle being stricter than its own checks?
 
Anton.




More information about the Python-list mailing list