howto check does module 'asdf' exist? (is available for import)
Jean-Paul Calderone
exarkun at divmod.com
Mon May 21 09:39:51 EDT 2007
On 21 May 2007 06:17:16 -0700, dmitrey <openopt at ukr.net> wrote:
>howto check does module 'asdf' exist (is available for import) or no?
>(without try/cache of course)
>Thx in advance, D.
>
You could use twisted.python.modules:
$ python
Python 2.4.3 (#2, Oct 6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.python.modules import getModule
>>> from sys import modules
>>> 'Numeric' in modules
False
>>> getModule('Numeric')
PythonModule<'Numeric'>
>>> 'Numeric' in modules
False
>>>
Jean-Paul
More information about the Python-list
mailing list