Import Python modules from a zipfile
class Test: def __init__(self): print 'hi'Now zip it:
zip test_mod.zip test_mod.pyNow fire up Python (at least 2.3), add the zipfile to your sys.path, and import the module.
$ python2.3 Python 2.3 (#1, Sep 13 2003, 00:49:11) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.insert(0, '/Users/stevej/test_mod.zip') >>> import test_mod >>> test_mod.__file__ '/Users/stevej/test_mod.zip/test_mod.py' >>> test_mod.Test() hiNot at easy as it could be but it's a solid first step. The ability to address arbitrary content in a zipfile (i.e. not just Python modules) would be a solid second step.
# — 24 November, 2004