The Voidspace Techie Blog

Gravatar $ 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!


Gravatar 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


Gravatar This is actually a fairly old trick. http://code.activestate.com/reci...recipes/497000/


Gravatar Not built into Python it isn't Jason.


Gravatar 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).


Gravatar Thanks Michael for leading me from twitter to this post.


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan