Commit bbeee552 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Add __iter__ method to HDF5File class

parent 5b63c2d3
......@@ -39,6 +39,9 @@ class HDF5File(HDF5File_C):
return self.has_key(x)
def __iter__(self):
return iter(self.keys())
def _is_string(s):
"""Returns ``True`` if the given object is a string
......@@ -480,6 +480,7 @@ def test_copy_constructor():
assert "/Test/Data" in shallow
assert hdf5.filename == shallow.filename
assert hdf5.keys() == shallow.keys()
assert [key for key in hdf5] == shallow.keys()
assert hdf5.cwd == shallow.cwd
assert not deep.has_group("/Test")
......@@ -257,6 +257,27 @@ the variable `my_array` as an arrayset using
:py:meth:``. In this case, each position readout
would return a 1D uint8 array instead of a 2D array.
Pythonic operations on HDF5 files
You can use some Pythonic opertations on :py:class:``.
You can iterate over :py:class:`` objects to get an
iterable of keys instead of calling
:py:meth:``. You can also use the ``in`` keyword
instead of calling :py:meth:``. For example:
.. doctest::
>>> keys = f.keys() # Get a list of keys
>>> keys == [key for key in f] # instead you can also iterate over keys
>>> f.has_key('arrayset')
>>> 'arrayset' in f # you can use the `in` operator instead of `has_key`
Array interfaces
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment