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

Tim Peters tim.peters at gmail.com
Mon Aug 2 19:15:20 CEST 2004


[Jim Fulton]
> I propose to add the following function to the imp module:
>
>   exists(module_name)
>
>      Test whether the named module can be found.

+1.  This can be much better than catching ImportError, for reasons
previously given.  site.py should be changed to use this to determine
whether sitecustomize exists (as is, if sitecustomize exists but
screws up by trying to import something that isn't on sys.path,
site.py suppresses the ImportError raised *by* sitecustomize; this is
bad).


More information about the Python-Dev mailing list