Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70497 > unrolled thread
| Started by | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| First post | 2014-04-22 12:29 +0200 |
| Last post | 2014-04-22 23:26 +1000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2014-04-22 12:29 +0200 |
| Subject | Strange syntax error, occurs only when script is executed directly |
| Message-ID | <mailman.9431.1398162667.18130.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-04-22 12:36 +0000 |
| Message-ID | <5356625a$0$29993$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #70497 |
On Tue, 22 Apr 2014 12:29:56 +0200, 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.
Are you sure about that? You ought to double check that /opt/local/bin/
python is what you think it is, and not (say) a symlink to a different
binary.
> These are the 15 first lines of the script:
>
> #! /opt/local/bin/python
This being Solaris, what happens if you remove the space between the hash-
bang and the path? On Linux it makes no difference, but Solaris tends to
be a bit more idiosyncratic about things like this.
[...]
> 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):'
That's not a Python syntax error, so its something else failing before
Python gets to see it. The only way I can reproduce this is to execute
Python code using sh:
[steve@ando ~]$ cat ./test2
class X(object):
pass
print X
[steve@ando ~]$ ./test2
./test2: line 1: syntax error near unexpected token `('
./test2: line 1: `class X(object):'
> Does anyone have an idea where I should look to fix this?
Ask your local Solaris expert :-)
This appears to be the same symptoms:
http://www.linuxmisc.com/12-unix-shell/581d028236386dae.htm
--
Steven D'Aprano
http://import-that.dreamwidth.org/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-04-22 22:52 +1000 |
| Message-ID | <mailman.9438.1398171515.18130.python-list@python.org> |
| In reply to | #70505 |
On Tue, Apr 22, 2014 at 10:36 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: >> These are the 15 first lines of the script: >> >> #! /opt/local/bin/python > > This being Solaris, what happens if you remove the space between the hash- > bang and the path? On Linux it makes no difference, but Solaris tends to > be a bit more idiosyncratic about things like this. I'm pretty sure the POSIX standard stipulates that a space there is optional. Should be no difference between "#!/" and "#! /" on any compliant OS. (But I can't right now find a citation for that, so I may be wrong.) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Andrew Cooper <root@127.0.0.1> |
|---|---|
| Date | 2014-04-23 02:28 +0100 |
| Message-ID | <ZGE5v.84443$RZ3.69217@fx19.am4> |
| In reply to | #70506 |
On 22/04/2014 13:52, Chris Angelico wrote: > On Tue, Apr 22, 2014 at 10:36 PM, Steven D'Aprano > <steve+comp.lang.python@pearwood.info> wrote: >>> These are the 15 first lines of the script: >>> >>> #! /opt/local/bin/python >> >> This being Solaris, what happens if you remove the space between the hash- >> bang and the path? On Linux it makes no difference, but Solaris tends to >> be a bit more idiosyncratic about things like this. > > I'm pretty sure the POSIX standard stipulates that a space there is > optional. Should be no difference between "#!/" and "#! /" on any > compliant OS. (But I can't right now find a citation for that, so I > may be wrong.) > > ChrisA > man execve 4.3BSD implicitly mandates a space given its description of the shebang line, while POSIX simply implies the presence of a space. I have recently had to check this point. All current kernel implementations I cared to check would strip whitespace around the interpreter, although Solaris was not one such implementation. ~Andrew
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-04-22 08:22 -0500 |
| Message-ID | <mailman.9441.1398172986.18130.python-list@python.org> |
| In reply to | #70505 |
On 2014-04-22 22:52, Chris Angelico wrote: > I'm pretty sure the POSIX standard stipulates that a space there is > optional. Should be no difference between "#!/" and "#! /" on any > compliant OS. (But I can't right now find a citation for that, so I > may be wrong.) I wondered this too, so went researching and found this: http://en.wikipedia.org/wiki/Shebang_%28Unix%29#Magic_number which said that there was actually some contention that the space was required, but that the specs state that both with-and-without are permissible. -tkc
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-04-22 23:26 +1000 |
| Message-ID | <mailman.9442.1398173207.18130.python-list@python.org> |
| In reply to | #70505 |
On Tue, Apr 22, 2014 at 11:22 PM, Tim Chase <python.list@tim.thechases.com> wrote: > On 2014-04-22 22:52, Chris Angelico wrote: >> I'm pretty sure the POSIX standard stipulates that a space there is >> optional. Should be no difference between "#!/" and "#! /" on any >> compliant OS. (But I can't right now find a citation for that, so I >> may be wrong.) > > I wondered this too, so went researching and found this: > > http://en.wikipedia.org/wiki/Shebang_%28Unix%29#Magic_number > > which said that there was actually some contention that the space was > required, but that the specs state that both with-and-without are > permissible. Yeah, I read the Wikipedia page, but was looking for a citable standards document, and didn't find one. (Which may just mean I didn't look hard enough. Wasn't going to spend an hour on it.) ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web