What I want to achieve is based on the voted answer for a previous question: Check if node exists in h5py
Basically I want to replace:
"/some/path" in h5File
with something like:
import re
re.compile(r'/some/[pattern]+') in h5File
What I want to achieve is based on the voted answer for a previous question: Check if node exists in h5py
Basically I want to replace:
"/some/path" in h5File
with something like:
import re
re.compile(r'/some/[pattern]+') in h5File
The in
keyword can't take a regex, but you could use list-comprehension or filter
built-in to get all keys from a dictionary that match a given regex.
E.g.
found_keys = [k for k in h5file if re.match(r'/some/[pattern]+', k)]
or
regex = re.compile(r'/some/[pattern]+')
found_keys = filter(regex.match, h5file)