[Python-Dev] New and Improved Import Hooks (original) (raw)

M.-A. Lemburg mal@lemburg.com
Thu, 05 Dec 2002 13:45:30 +0100


Just van Rossum wrote:

Martin v. L=F6wis wrote: =20 =20

"M.-A. Lemburg" <mal@lemburg.com> writes:

But why store the import objects in sys.path and not in some auxilliary dictionary instead ? What would be the advantage of doing so? And, if this is done: How can I add my own custom import mechanism to sys.path? The machinery to replace strings in sys.path is only available for zip files, all other hooks must add their objects to sys.path directly. =20 =20 +1 =20 With MAL's idea you'd need to write =20 p =3D ... sys.importers[p] =3D myimporter(p) sys.path.append(p)

Hmm, I was thinking of:

sys.register_importer(myimporter) sys.path.append(p)

myimporter would then either be asked for a suitable suffix or prefix to use in matching or the importer would simply call myimporter.match() during the sys.path scan.

instead of =20 sys.path.append(myimporter(p))

Sounds like the classical "you need one more line than me" argument ;-)

--=20 Marc-Andre Lemburg CEO eGenix.com Software GmbH


eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/