Strange syntax error, occurs only when script is executed directly

Tim Golden mail at timgolden.me.uk
Tue Apr 22 06:35:43 EDT 2014


On 22/04/2014 11:29, Antoon Pardon wrote:
> I am workin on a solaris 11 machine. The python version is 2.7.6
> path to python is /opt/local/bin/python.
> 
> These are the 15 first lines of the script:
> 
> #! /opt/local/bin/python
> 
> class vslice(object):
> 
>         def __init__(self, fun):
>                 self.fun = fun
> 
>         def __getitem__(self, inx):
>                 if not isinstance(inx, tuple):
>                         inx = inx,
>                 #if
>                 return self.fun(*inx)
>         #end __getitem__
> #end __vslice__
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> Now if I execute the script by explicitly calling the interpreter
> everything works fine.
> 
> # /opt/local/bin/python /usr/local/bin/ldapwatch /opt/local/log/openldap.log | head
> Apr 21 15:12:38 conn=110982 fd=125 ACCEPT from IP=10.0.59.10:46238 (IP=10.0.128.65:389)
> Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" method=128
> Apr 21 15:12:38 conn=110982 op=0 BIND dn="uid=anonymous,ou=local,ou=people,o=global" mech=SIMPLE ssf=0
> Apr 21 15:12:38 conn=110982 op=0 RESULT tag=97 err=0 text=
> Apr 21 15:12:38 conn=110982 op=1 SRCH base="ou=people,o=global" scope=2 deref=0 filter="(uid=anonymous)"
> Apr 21 15:12:38 conn=110982 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
> Apr 21 15:12:38 conn=110982 op=2 UNBIND
> Apr 21 15:12:38 conn=110982 fd=125 closed
> ====
> Apr 21 15:12:57 conn=110983 fd=125 ACCEPT from IP=10.1.28.235:39616 (IP=10.0.128.65:389)
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> 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 have no idea what is going on here. The persmision for /usr/local/bin/ldapwatch look fine:
> # ls -l /usr/local/bin/ldapwatch -rwxr-xr-x 1 root root 2092 Apr 22 10:05 /usr/local/bin/ldapwatch

Look for a dodgy line-feed / cr (or some other non-visible control
character) at the end of the shebang line?

TJG




More information about the Python-list mailing list