Skip to content

Instantly share code, notes, and snippets.

@angelworm
Last active Aug 29, 2015
Embed
What would you like to do?
モジュールが存在するときにのみimportしてくれるやつ
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