Newbie getting desperate with for

Chris Rebert clp2 at
Thu Feb 17 03:39:01 EST 2011

On Thu, Feb 17, 2011 at 12:27 AM, Werner <wdahn at> wrote:
> I have a trivially simple piece of code called
> ____________________________________________________
> while True:
>    i = 0
>    for i in range(10):
>        break
> _____________________________________________________
> It runs fine with Eric but when I try to run it from shell...
>> ./
> ./ line 4: syntax error near unexpected token `('
> ./ line 4: `    for i in range(10):'
> I've tried this on openSuse 11.3 and Kubuntu 10.04, both use Python
> version 2.6.5, both show the above.
> Before I tear out my hair any more (only 3 left) I thought I'd ask here
> what I am doing wrong.

Looks like it's being run as a shell script rather than through the
Python interpreter (hence why the error is not in the form of an
exception with a traceback).

Try adding:

#!/usr/bin/env python

as the first line in your file. This tells the shell to run the script
using Python.

Or alternatively, instead of:




which likewise explicitly invokes the Python interpreter.


More information about the Python-list mailing list