Strange syntax error, occurs only when script is executed directly

Frank Millman frank at chagford.com
Tue Apr 22 06:42:27 EDT 2014


"Antoon Pardon" <antoon.pardon at rece.vub.ac.be> wrote in message 
news:535644A4.6060901 at rece.vub.ac.be...
>I am workin on a solaris 11 machine. The python version is 2.7.6
> path to python is /opt/local/bin/python.
>
[...]
>
> Now if I execute the script by explicitly calling the interpreter
> everything works fine.
>
[...]
>
> However if I call the script directly and want the #! line do its work I 
> get the following error.
>
> # /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head
> /usr/local/bin/ldapwatch: line 3: syntax error near unexpected token `('
> /usr/local/bin/ldapwatch: line 3: `class vslice(object):'
>

I had something similar and it turned out that my script had 'CRLF' line 
endings instead of 'LF' only, and this caused the problem. I believe that 
the problem has nothing to do with python, but with how the shell interprets 
the '#!' line.

My editor allows me to re-save a file using a different format, so I saved 
it as 'unix', reran it, and it worked.

HTH

Frank Millman






More information about the Python-list mailing list