|
|
|
$ cat > __main__.py
print('hi there')
^D
$ zip test.zip __main__.py
adding: __main__.py (stored 0%)
$ cat > hashbang.txt
#!/usr/bin/env python3.0
^D
$ cat hashbang.txt test.zip > my_exec
$ chmod +x my_exec
$ ./my_exec
hi there
$
Very nice indeed!
Floris Bruynooghe |
Homepage |
08/12/08 - 11:37 am | #
|
|
That's pretty neat.
I was curious so I did the next obvious thing:
$ unzip my_exec
Archive: my_exec
warning [my_exec]: 23 extra bytes at beginning or within zipfile
(attempting to process anyway)
extracting: __main__.py
Richard Jones |
Homepage |
08/12/08 - 11:50 am | #
|
|
This is actually a fairly old trick. http://code.activestate.com/reci...recipes/497000/
Jason Baker |
Homepage |
08/12/09 - 12:43 am | #
|
|
Not built into Python it isn't Jason. 
Michael Foord |
Homepage |
08/12/09 - 10:25 am | #
|
|
I was trying to hack this to work in Python 2.5, but failed, when I came upon the discussion for 2.6. So I'm glad to see it in, I'll try at some point to use it to make pip pybundles self-extracting and installable (basically putting pip and virtualenv into the zip itself).
Ian Bicking |
Homepage |
08/12/11 - 5:33 am | #
|
|
Thanks Michael for leading me from twitter to this post.
Domingo Aguilera |
Homepage |
08/12/15 - 5:25 pm | #
|
|
|
Commenting by HaloScan
|