Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:error': 0.03; 'syntax': 0.04; 'explicitly': 0.05; 'interpreter': 0.05; 'received:134': 0.05; 'only,': 0.07; 'subject:script': 0.09; 'worked.': 0.09; 'python': 0.11; 'skip:= 70': 0.12; 'wrote': 0.14; 'fine.': 0.16; 'grep': 0.16; 'newlines': 0.16; 'subject:when': 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'format,': 0.24; 'file.': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'specifically': 0.29; 'characters': 0.30; 'allows': 0.31; 'file': 0.32; 'problem': 0.35; 'problem.': 0.35; 'something': 0.35; 'editor': 0.35; 'but': 0.35; 'version': 0.36; 'machine.': 0.36; "didn't": 0.36; 'shows': 0.36; 'similar': 0.36; 'error.': 0.37; 'turn': 0.37; 'to:addr:python- list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'more': 0.64; 'different': 0.65; 'believe': 0.68; 'anything.': 0.68; 'frank': 0.68; 'caused': 0.69; 'special': 0.74; 'pardon': 0.84; 'troublesome': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAJhRVlOGuA9G/2dsb2JhbABZhzvBB4EtgxkBAQUjVRELGAICBRYLAgIJAwIBAgFFEwYCAhaIJ6kYnROGFBeBKY00FoJZgUkBA5hwhkKMEIMz Date: Tue, 22 Apr 2014 13:26:46 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Strange syntax error, occurs only when script is executed directly References: <535644A4.6060901@rece.vub.ac.be> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 74 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398166020 news.xs4all.nl 2832 [2001:888:2000:d::a6]:37321 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70500 On 22-04-14 12:42, Frank Millman wrote: > "Antoon Pardon" wrote in message > news:535644A4.6060901@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