Strange syntax error, occurs only when script is executed directly
Antoon Pardon
antoon.pardon at rece.vub.ac.be
Tue Apr 22 07:26:46 EDT 2014
On 22-04-14 12:42, Frank Millman wrote:
> "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.
My editor shows me a CR in the file. Just to be sure I used od -c on the file,
this is the result:
# od -c /usr/local/bin/ldapwatch | head -30
0000000 # ! / o p t / l o c a l / b i
0000020 n / p y t h o n \n \n c l a s s
0000040 v s l i c e ( o b j e c t ) : \n
0000060 \n \t d e f _ _ i n i t _ _ ( s
0000100 e l f , f u n ) : \n \t \t s e l
0000120 f . f u n = f u n \n \n \t d e
0000140 f _ _ g e t i t e m _ _ ( s e
0000160 l f , i n x ) : \n \t \t i f n
0000200 o t i s i n s t a n c e ( i n
0000220 x , t u p l e ) : \n \t \t \t i n
0000240 x = i n x , \n \t \t # i f \n \t
0000260 \t r e t u r n s e l f . f u n
0000300 ( * i n x ) \n \t # e n d _ _ g
0000320 e t i t e m _ _ \n # e n d _ _
0000340 v s l i c e _ _ \n \n @ v s l i c
0000360 e \n d e f p r o j e c t ( l s
0000400 t , * a r g v ) : \n \t r e s u
0000420 l t = [ ] \n \t f o r a r g
0000440 i n a r g v : \n \t \t t m p
0000460 = l s t [ a r g ] \n \t \t i f
0000500 i s i n s t a n c e ( a r g ,
0000520 s l i c e ) : \n \t \t \t r e s u l
0000540 t . e x t e n d ( t m p ) \n \t \t
0000560 e l s e : \n \t \t \t r e s u l t .
0000600 a p p e n d ( t m p ) \n \t \t # i
0000620 f \n \t # f o r \n \t r e t u r n
0000640 r e s u l t \n # e n d p r o j
0000660 e c t \n \t \t \n i m p o r t s y
0000700 s \n \n d e f I s N o n e ( a r
0000720 g ) : \n \t r e t u r n a r g
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I see nothing that can cause a problem. I tried to search more specifically
for troublesome characters but that didn't turn up anything.
# od -c /usr/local/bin/ldapwatch | head -30 | grep '\\[^nt]'
#
So all special characters are either newlines or tabs.
--
Antoon Pardon
More information about the Python-list
mailing list