Skip to content

Instantly share code, notes, and snippets.

@hiqua
Created January 13, 2017 10:25
Show Gist options
  • Save hiqua/d95e706922ad906fe9a02a01d7a2290c to your computer and use it in GitHub Desktop.
Save hiqua/d95e706922ad906fe9a02a01d7a2290c to your computer and use it in GitHub Desktop.
Load modules in when starting the python interpreter, if available.
MOD_LIST = [
['math'],
['tensorflow', 'tf'],
]
def load_module(module):
import importlib
assert len(module) in (1, 2), module
try:
globals()[module[-1]] = importlib.import_module(module[0])
except ImportError:
print("Module {} not loaded".format(module[0]))
for module in MOD_LIST:
load_module(module)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment