[Python-Dev] Add a -z interpreter flag to execute a zip file
James Y Knight
foom at fuhm.net
Fri Jul 13 16:14:44 CEST 2007
On Jul 12, 2007, at 1:58 PM, Phillip J. Eby wrote:
> I don't have any particular objection to using runpy for this, but I
> believe that this shebang line won't actually work on certain non-BSD
> OSes, such as most Linux versions, which allow you to have at most
> *one* argument to a #! line, and will combine anything after the
> executable portion into a single argument. This means that the only
> workable form of this line for cross-platform use is:
>
> #!/usr/bin/python2.6 -z
>
> And of course that won't work if Python is somewhere else. You can't
> both use env to invoke Python, *and* expect arguments to work. env
> will receive a single argument of "python -m runpy -p", which it will
> then try to invoke. On Mac OS and various other BSDs, your example
> will work correctly, but it won't work most anywhere else, as few
> OSes actually support passing individual arguments from a #! line.
> See:
>
> http://www.in-ulm.de/~mascheck/various/shebang/
Ah, but you *can* use some quite clever quoting to get that effect.
E.g. this starts up python with /usr/bin/env and a -O argument:
#!/bin/sh
""""exec /usr/bin/env python -O $0 "$@";" """
Credit for this trick originally belong to someone else: I found this
on some website, but I don't know where anymore.
I'll leave it as a exercise to the reader to figure out how it works. :)
James
More information about the Python-Dev
mailing list