Fork me on GitHub

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保存原来的变量名。

posted on 2014-02-21 17:12  huashiyiqike  阅读(3250)  评论(0编辑  收藏  举报