D
dmitrey
howto check does module 'asdf' exist (is available for import) or no?
(without try/cache of course)
Thx in advance, D.
(without try/cache of course)
Thx in advance, D.
dmitrey said:howto check does module 'asdf' exist (is available for import) or no?
(without try/cache of course)
howto check does module 'asdf' exist (is available for import) or no?
(without try/cache of course)
try :howto check does module 'asdf' exist (is available for import) or no?
Oops sorry, you wanted it done in some non-obvious way! Why?!(without try/cache of course)
You can generalise this, but at the expense of a couple of exec
statements:
def is_module_available (module) :
try :
exec('import %s' % module)
exec('del %s' % module)
except ImportError :
return False
else :
return True
Asun Friere said:try :
import asdf
del asdf
except ImportError :
print "module asdf not available"
else :
print "module asdf available for loading"
kaens said:I think that's there because you just wanted to check if it was
available for import, implying that you didn't actually want to import
it right then.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.