[Python-Dev] Proposed Python api for testing whether a module exists (original) (raw)
Jim Fulton jim at zope.com
Mon Aug 2 19:37:10 CEST 2004
- Previous message: [Python-Dev] RE: [Python-checkins] python/dist/src/Objects listobject.c, 2.218, 2.219
- Next message: [Python-Dev] Proposed Python api for testing whether a module exists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Anthony Baxter wrote:
Jim Fulton wrote:
If a dotted module name is given, then parent modules will be imported if they haven't already been imported. So you might end up spelling something like: _if imp.exists('pkg') and imp.exists('pkg.subpkg') _ and imp.exists('pkg.subpkg.module'): to avoid an importerror on the parent module?
No. If pkg doesn't exist then exists will report False.
Here's new wording:
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 and parent modules exist,
then the parent modules will be imported if they haven't
already been imported.
Thanks,
Jim
-- Jim Fulton mailto:jim at zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
- Previous message: [Python-Dev] RE: [Python-checkins] python/dist/src/Objects listobject.c, 2.218, 2.219
- Next message: [Python-Dev] Proposed Python api for testing whether a module exists
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]