Skip to content

Instantly share code, notes, and snippets.

@sudorandom
Created March 5, 2014 23:56
Show Gist options
  • Save sudorandom/9379323 to your computer and use it in GitHub Desktop.
Save sudorandom/9379323 to your computer and use it in GitHub Desktop.
Multi Multiple Import
PARSERS = [('pkg_resources', 'parse_version'), ('distutils.version', 'StrictVersion')]
def get_parse_fn():
for parser_module, parser in PARSERS:
try:
return getattr(importlib.import_module(parser_module), 'parser')
except ImportError:
pass
raise Exception("Couldn't find a thing to do the thing")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment