Skip to content

Instantly share code, notes, and snippets.

@gchiam
Last active October 15, 2015 03:50
Show Gist options
  • Save gchiam/c8e2ce83cf9cfc87fc1f to your computer and use it in GitHub Desktop.
Save gchiam/c8e2ce83cf9cfc87fc1f to your computer and use it in GitHub Desktop.
fallback import (python3 only)
# spam.py
try:
import foo
except ImportError:
import simplefoo as foo
# if the module foo can be found, do import
if find_spec('foo'):
import foo
else:
import simplefoo as foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment