[Python-Dev] imputil and modulefinder replacements (original) (raw)

Gordon McMillan gmcm@hypernet.com
Fri, 5 Oct 2001 15:20:33 -0400


[Greg Ward]

The only import hook I'm familiar with is Quixote, where we have defined a Python dialect called PTL (Python Template Language, used to embed HTML [or other text] in Python). Install Quixote's import hook, and you can import .ptl files just like .py files. It's very handy. Out of curiosity, does anyone know of any other import hooks like this out there -- ie. import something that is not strictly Python. (It sounds like most import hooks/hacks deal with the location of the .py files to import. Quixote doesn't touch that, but it adds the ability to import not-quite-Python source files.)

I know of import hooks like that, but in 1000+ emails from Installer users, no one has ever attempted to distribute an app that uses one. If the hook writes out a .pyc, then the hook is pretty much developer-only, anyway.

Note that my experience of this in Java was largely negative, because Java doesn't have a standard way of putting .class files in the filesystem (AFAIK) -- so everything has to be in a .jar file, and those .jar files can be anywhere you please.

Huh? Jar files don't date from day 1 - for .class files it works almost like Python.

So you end up with a mile-long CLASSPATH that's very fragile and forever needing fixing. As long as most Python modules are accessed the ordinary way (files in a directory), then Python won't have a problem. But if somebody makes a Python installation with "stdlib.zip", "distutils.zip", "mxDateTime.zip", etc. etc., then the poor users will be in the same boat as Java users.

I think the only difference is that Python goes to considerable effort (and expense) to work out a sys.path before considering PYTHONPATH.