Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.io.base
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.io.base
Commits
bbeee552
Commit
bbeee552
authored
8 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add __iter__ method to HDF5File class
parent
5b63c2d3
No related branches found
No related tags found
1 merge request
!17
Add `__iter__` method to the HDF5File class
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/io/base/__init__.py
+3
-0
3 additions, 0 deletions
bob/io/base/__init__.py
bob/io/base/test_hdf5.py
+1
-0
1 addition, 0 deletions
bob/io/base/test_hdf5.py
doc/guide.rst
+21
-0
21 additions, 0 deletions
doc/guide.rst
with
25 additions
and
0 deletions
bob/io/base/__init__.py
+
3
−
0
View file @
bbeee552
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
bob/io/base/test_hdf5.py
+
1
−
0
View file @
bbeee552
...
...
@@ -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
"
)
...
...
This diff is collapsed.
Click to expand it.
doc/guide.rst
+
21
−
0
View file @
bbeee552
...
...
@@ -257,6 +257,27 @@ the variable `my_array` as an arrayset using
:py:meth:`bob.io.base.HDF5File.read`. 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:`bob.io.base.HDF5File`.
You can iterate over :py:class:`bob.io.base.HDF5File` objects to get an
iterable of keys instead of calling
:py:meth:`bob.io.base.HDF5File.keys`. You can also use the ``in`` keyword
instead of calling :py:meth:`bob.io.base.HDF5File.has_key`. For example:
.. doctest::
>>> keys = f.keys() # Get a list of keys
>>> keys == [key for key in f] # instead you can also iterate over keys
True
>>> f.has_key('arrayset')
True
>>> 'arrayset' in f # you can use the `in` operator instead of `has_key`
True
Array interfaces
----------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment