[Python-Dev] Add a -z interpreter flag to execute a zip file

Andy C andychup at gmail.com
Thu Jul 12 17:11:05 CEST 2007

On 7/12/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 10:09 AM 7/12/2007 +0200, Martin v. Löwis wrote:
> >"" should not be removed from sys.path. It is *not* meant to be
> >the current directory, but the directory where the main script
> >lives.
> Right; it should be replaced with the zipfile path instead.

That's indeed what the current implementation does, replacing "" with
the zip file.

> I would personally rather see this option defined as simply placing a
> directory at the front of sys.path, and perhaps defining a default -m
> value of __main__, unless overrridden.  Being able to use the option

Actually, that's a good idea, and it does work with my current
implementation [1], although we'd have to change the name __zipmain__.
 Is __main__ a good idea considering that is used for something
similar but implemented completely differently (the module name)?  I
thought about using __main__, but decided on __zipmain__ since seemed
to be more explicit and reduce potential conflicts.

To be clear to other readers, the convention would be that if a
__main__.py file exists at the root of a directory, then the whole
directory is considered an executable python program.

> more than once would be nice, too.  On Windows, you can't set an
> environment variable on the same line as a command, so this would
> give you a one-liner way of setting sys.path and running an application.
> I do not see a reason to make this option zipfile-specific in any
> way, though; it's just as useful (and sometimes more so) to be able
> to distribute an application as a directory, since that lets you use
> .pyd, .so, .dll etc. without needing the egg cache system for using those.

Yes, the dynamic library importing is nice.


andychu testprog$ find

andychu testprog$ ../python -z .
lib module here
argv: ['.']
andychu testprog$

More information about the Python-Dev mailing list