Simplify read_h5meta
This commit is contained in:
parent
3e256b1707
commit
900d8a37b5
@ -11,20 +11,19 @@ def read_h5meta(filepath):
|
|||||||
dict: A dictionary with section names and their content.
|
dict: A dictionary with section names and their content.
|
||||||
"""
|
"""
|
||||||
h5meta_content = dict()
|
h5meta_content = dict()
|
||||||
with open(filepath, "r") as h5meta_file:
|
with open(filepath) as h5meta_file:
|
||||||
line = h5meta_file.readline()
|
section = None
|
||||||
while line:
|
for line in h5meta_file:
|
||||||
|
line = line.strip()
|
||||||
if line.startswith("#begin "):
|
if line.startswith("#begin "):
|
||||||
# read section
|
section = line[len("#begin "):]
|
||||||
section = line[7:-1] # len("#begin ") = 7
|
|
||||||
h5meta_content[section] = []
|
h5meta_content[section] = []
|
||||||
line = h5meta_file.readline()
|
|
||||||
while not line.startswith("#end"):
|
|
||||||
h5meta_content[section].append(line[:-1])
|
|
||||||
line = h5meta_file.readline()
|
|
||||||
|
|
||||||
# read next line after section's end
|
elif line.startswith("#end"):
|
||||||
line = h5meta_file.readline()
|
section = None
|
||||||
|
|
||||||
|
elif section:
|
||||||
|
h5meta_content[section].append(line)
|
||||||
|
|
||||||
return h5meta_content
|
return h5meta_content
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user