#! independent of location of python binary
Dave Brueck
dbrueck at edgix.com
Wed Sep 20 11:26:01 EDT 2000
#!/usr/bin/env python
----- Original Message -----
From: "Harald Kirsch" <kirschh at lionbioscience.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, September 20, 2000 9:16 AM
Subject: #! independent of location of python binary
>
> In Tcl I write
>
> #!/bin/sh
> # \
> exec tclsh "$0" ${1+"$@"}
>
> and the tclsh will be found along the path.
>
> How can I do this in python. I tried
>
> #!/bin/sh
> exec python $@ -c "`tail +3 $0`"
>
> but this is of course suboptimal because sys.argv[0] becomes `-c'.
>
> The next one was:
>
> #!/bin/sh
> exec python $@ -c "import sys;sys.argv[0]='$0';`tail +3 $0`"
>
> but things start to become really messy here. In addition, it does not
> preserve semantics because it forces the import of sys.
>
> Harald Kirsch
> --
> ----------------+------------------------------------------------------
> Harald Kirsch | kirschh at lionbioscience.com | We make the tools to
> LION Bioscience | +49 6221 4038 172 | reverse engineer nature.
> *** Please: Never Ever Mail Me Copies Of Your Posts ***
> --
> http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list