Numpy allows to export several arrays in a single npz file which can be loaded then, using for instance:
infile = "somefile.npz"
inData = np.load( infile)
print( inData.files) #will list all the arrays importable from the file
I am interested in function that could load all the data and conserve the naming before exportation in one call.
I can do it `inline' by:
infile = "somefile.npz"
inData = np.load( infile)
for varName in inData.files:
exec(varName + " = inData[\"" + varName + "\"]")
which seems to work. But as I would like to make use of this in multiple places, it does not seem to work when moved into a function:
def importEverything( infile):
#imports everything inside the npz input file and keeps the variable in the global namespace
It seems that the scope of variables cannot extend from this function's local scope.
It seems that I am misunderstanding something about Python here. Is it possible to do? Is it non advisable?
globals()is discouraged.