Created
March 28, 2013 00:39
-
-
Save kmike/5259525 to your computer and use it in GitHub Desktop.
use_speedups_if_available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def use_speedups_if_available(original, module_name, func_name): | |
try: | |
mod = __import__(module_name, fromlist=[func_name]) | |
return getattr(mod, func_name), original | |
except ImportError: | |
return original, original | |
# ------------- Example usage ------------ | |
def foo(): | |
# ... pure-Python version | |
foo, _foo_orig = use_speedups_if_available(foo, 'nltk_speed.subpackage', 'foo') | |
# ---------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment