~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderplugins/io_hdf5.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2014-05-29 09:06:26 UTC
  • mfrom: (1.1.21) (18.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140529090626-f58t82g0n5iewaxu
Tags: 2.3.0~rc+dfsg-1~experimental2
* Add spyder-common binary package for all the python2,3 common files
* debian/path
  - 0001-fix-documentation-installation.patch (deleted)
  + 0001-fix-spyderlib-path.patch (new)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
TODO: Check issues with valid python names vs valid h5f5 names
29
29
"""
30
30
 
 
31
from __future__ import print_function
 
32
 
31
33
try:
32
34
    # Do not import h5py here because it will try to import IPython,
33
35
    # and this is freezing the Spyder GUI
39
41
        import h5py
40
42
        def get_group(group):
41
43
            contents = {}
42
 
            for name, obj in group.iteritems():
 
44
            for name, obj in list(group.items()):
43
45
                if isinstance(obj, h5py.Dataset):
44
46
                    contents[name] = np.array(obj)
45
47
                elif isinstance(obj, h5py.Group):
53
55
            contents = get_group(f)
54
56
            f.close()
55
57
            return contents, None
56
 
        except Exception, error:
 
58
        except Exception as error:
57
59
            return None, str(error)
58
60
            
59
61
    def save_hdf5(data, filename):
60
62
        import h5py
61
63
        try:
62
64
            f = h5py.File(filename, 'w')
63
 
            for key, value in data.iteritems():
 
65
            for key, value in list(data.items()):
64
66
                f[key] = np.array(value)
65
67
            f.close()
66
 
        except Exception, error:
 
68
        except Exception as error:
67
69
            return str(error)            
68
70
except ImportError:
69
71
    load_hdf5 = None
79
81
 
80
82
if __name__ == "__main__":
81
83
    data = {'a' : [1, 2, 3, 4], 'b' : 4.5}
82
 
    print save_hdf5(data, "test.h5")
83
 
    print load_hdf5("test.h5")
 
84
    print(save_hdf5(data, "test.h5"))
 
85
    print(load_hdf5("test.h5"))