Martin v. L=F6wis wrote: > "M.-A. Lemburg" <mal@lemburg.com> writes: >=20 >=20 >>But why store the import objects in sys.path and not in >>some auxilliary dictionary instead ? >=20 >=20 > What would be the advantage of doing so? Real strings in a real dictionary. > 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. Well, that's what I tried to solve in the sketch I posted earlier (slightly modified to meet Fredrik's requirements): 1. User programs register import hooks based on suffixes which are used to match the entries in sys.path, e.g. ".zip" for ZIP importers (caching could help in improving the mapping performance; this is where the auxilliary dictionary comes into play). 2. When Python sees an import request, it scans sys.path and creates hook objects for each entry which it then calls to say "go look and check whether you have module X" until one of the hooks succeeds. 3. Python then uses the hook object to complete the import in much a similar way as e.g. SAX parsers call out to event handlers. --=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/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4