Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70497

Strange syntax error, occurs only when script is executed directly

Date 2014-04-22 12:29 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Subject Strange syntax error, occurs only when script is executed directly
Newsgroups comp.lang.python
Message-ID <mailman.9431.1398162667.18130.python-list@python.org> (permalink)

Show all headers | View raw


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


Does anyone have an idea where I should look to fix this?

-- 
Antoon Pardon

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Strange syntax error, occurs only when script is executed directly Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-04-22 12:29 +0200
  Re: Strange syntax error, occurs only when script is executed directly Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-22 12:36 +0000
    Re: Strange syntax error, occurs only when script is executed directly Chris Angelico <rosuav@gmail.com> - 2014-04-22 22:52 +1000
      Re: Strange syntax error, occurs only when script is executed directly Andrew Cooper <root@127.0.0.1> - 2014-04-23 02:28 +0100
    Re: Strange syntax error, occurs only when script is executed directly Tim Chase <python.list@tim.thechases.com> - 2014-04-22 08:22 -0500
    Re: Strange syntax error, occurs only when script is executed directly Chris Angelico <rosuav@gmail.com> - 2014-04-22 23:26 +1000

csiph-web