[Python-Dev] Proposed Python api for testing whether a module exists

Phillip J. Eby pje at telecommunity.com
Mon Aug 2 19:01:02 CEST 2004


At 12:32 PM 8/2/04 -0400, Jim Fulton wrote:

>I propose to add the following function to the imp module:
>
>   exists(module_name)
>
>      Test whether the named module can be found.
>
>      This method should be used when you want to perform
>      alternate actions depending on whether a module is available.
>
>      Returns True of the module can be found and False otherwise.
>      A True return value does not guarentee that the module will be
>      importable.  The module will not be imported as a result of
>      calling exists, but parent modules may be.
>
>      If a dotted module name is given, then parent modules will be
>      imported if they haven't already been imported.
>
>
>If there are no objections, I'll try to get this in before Wednesday night.

Is this intended to work in the presence of import hooks?  In particular, 
all the hooks offered by PEP 302, but also systems like 'iu', 'imputil', etc.

Or, more specifically, will this be implemented in terms of the PEP 302 
importer/loader protocols, or will those protocols need extending in order 
to allow such loaders (e.g. zipimport) to work with this new function?



More information about the Python-Dev mailing list