On Jan 26, 2010, at 3:20 PM, Ian Bicking wrote:
> Sadly you can't then do:
>
> chmod +x mz.py
> ./mz.py
Unless I missed some subtlety earlier in the conversation, yes you can :).
> because it doesn't have "#!/usr/bin/env python" like typical executable
> Python scripts have. You can put the shebang line at the beginning of the
> zip file, and zip will complain about it but will still unpack the file, but
> it won't be runnable as Python won't recognize it as a zip anymore.
python 2.6's zipfile module can cope with a shebang line in a zip file just
fine, and since this is the first version of Python which supports this
feature, that means the following works just fine (tested on OS X and Linux):
$ echo '#!/usr/bin/python
> ' > header.txt
$ echo 'import sys; sys.stdout.write("Hello, world!\n")' > __main__.py
$ zip go.zip __main__.py
adding: __main__.py (deflated 2%)
$ cat header.txt go.zip > go.py
$ chmod a+x go.py
$ ./go.py
Hello, world!
This use-case was specifically mentioned on
<http://bugs.python.org/issue1739468>, too.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com