program works as a script, not interactively

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon May 17 16:18:42 EDT 2004


Philip Carter wrote:
> Hello there,
> 
> I am using:
> Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
> 
> on a win2k box.
> 
> I have the following piece of python code:
> 
(snip code)

> When I save in a file - terry.py and run it:
> python terry.py
> it works fine.
> 
> However, if I try and paste it into an interactive python window, I get
> the following error:
> 
> ... outFile.close() # close the output file
>   File "<stdin>", line 14
>     outFile.close() # close the output file
>           ^
> SyntaxError: invalid syntax
> 
> Any idea why this is?

Probably a problem with indentation... I sometime have this kind of 
problem when copy/pasting pieces of code in the interpreter.

Bruno




More information about the Python-list mailing list