I want to load all npy/npz files into my interactive python shell, so I don't have to go:
var1 = np.load('var1.npy')
for each one. I made this script, but it doesn't work because it the variables namespace is just within the script (pretend the indenting is correct). What is the right way to do this?
def load_all():
import numpy as np
from os import listdir
from os.path import isfile, join
from os import getcwd
mypath = getcwd()
print 'loading all .npy and .npz files from ',mypath
files = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
for f in files:
if f[-4:] in ('.npy','.npz'):
name = f[:-4]+'_'+f[-3:]
print 'loading', f, 'as', name
var = np.load(f)
exec(name + " = var")