diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-15 08:17:12 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-15 08:17:12 +0000 |
| commit | 4fa5025d7424bd0c8da6a2f3a73dac0512a0e98d (patch) | |
| tree | a8d59535ab327167787c42904f1f75979ae08a37 /openstack/common/importutils.py | |
| parent | 859cc3df24751e4fb0acda8643d4feee10c3b39a (diff) | |
| parent | 33b12d3c18a35f85785227267347f9ac7f7273a4 (diff) | |
| download | oslo-4fa5025d7424bd0c8da6a2f3a73dac0512a0e98d.tar.gz oslo-4fa5025d7424bd0c8da6a2f3a73dac0512a0e98d.tar.xz oslo-4fa5025d7424bd0c8da6a2f3a73dac0512a0e98d.zip | |
Merge "Implement importutils.try_import."
Diffstat (limited to 'openstack/common/importutils.py')
| -rw-r--r-- | openstack/common/importutils.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/openstack/common/importutils.py b/openstack/common/importutils.py index 2a28b45..9dec764 100644 --- a/openstack/common/importutils.py +++ b/openstack/common/importutils.py @@ -57,3 +57,11 @@ def import_module(import_str): """Import a module.""" __import__(import_str) return sys.modules[import_str] + + +def try_import(import_str, default=None): + """Try to import a module and if it fails return default.""" + try: + return import_module(import_str) + except ImportError: + return default |
