[h5py] 183/455: Implement get, set_default
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.
commit e6d6d97c82160f3cae1a141a7d540dbe0e309eb1
Author: andrewcollette <andrew.collette at gmail.com>
Date: Mon Dec 15 06:46:17 2008 +0000
Implement get, set_default
---
h5py/highlevel.py | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 3b8d075..e09df83 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -159,6 +159,32 @@ class _DictCompat(object):
for x in self:
yield (x, self[x])
+ def get(self, name, default):
+ """ Retrieve the member, or return default if it doesn't exist """
+ with self._lock:
+ if name in self:
+ return self[name]
+ return default
+
+ def setdefault(self, name, default):
+ """ Retrieve the member, setting it to default if it doesn't exist.
+
+ Be careful; unlike the get() method, the returned object is *not*
+ generally the provided default object. The equivalent operation is:
+
+ obj[name] = default
+ return obj[name]
+
+ For groups, the returned object is always a Group, Dataset or
+ Datatype. For attributes, the returned object is always a NumPy
+ scalar or array.
+
+ Consider using Group.require_group or Group.require_dataset instead.
+ """
+ with self._lock:
+ if not name in self:
+ self[name] = default
+ return self[name]
class Group(HLObject, _DictCompat):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git
More information about the debian-science-commits
mailing list