1 from scipy import io 2 dataset = io.loadmat("a.mat") 3 exclude = ['__globals__', '__header__', '__version__'] 4 for obj in dataset.keys(): 5 if obj not in exclude: 6 print obj+'=dataset["'+obj+'"]' 7 exec(obj+'=dataset["'+obj+'"]') 8 exec 'print '+ obj
obj是变量名的str,需要用exec保存原来的变量名。