Last active
August 29, 2015 14:01
-
-
Save angelworm/d5000bf279f564acb92d to your computer and use it in GitHub Desktop.
モジュールが存在するときにのみimportしてくれるやつ
This file contains 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 load_module(m): | |
import imp | |
try: | |
f, p,d = imp.find_module(m) | |
return imp.load_module(m, f, p, d) | |
except: | |
return None | |
random = load_module("random") | |
hoge = load_module("hoge") | |
if False: | |
print(hoge.message()) | |
else: | |
print(str(random.random())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment