I am trying to write a function, which is itself loaded, to quickly import a bunch of modules globally.
I thought that, essentially, loaded modules could be treated as variables so I tried:
def loadMods(): global np import numpy as np and when I loaded numpy (calling np) there was no problem.
What I then did was to create a separate .py file called loadTest containing
# loadTest module # coding: utf-8 def loadMod(): global np import numpy as np Then attempted to import numpy using this .py file in python (2.7):
import loadTest loadTest.loadMod() but now when attempting calling np I get
File "<stdin>", line 1, in <module> NameError: name 'np' is not defined Why does this occur? Any help or alternative ways of doing this would be much appreciated. Thanks a bunch :)
npavailable inside yourloadTestmodule, which doesn't really help at all.