Simplify read_h5meta

This commit is contained in:
usov_i 2020-08-31 19:03:52 +02:00
parent 3e256b1707
commit 900d8a37b5

View File

@ -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:
if line.startswith("#begin"): line = line.strip()
# read section if line.startswith("#begin "):
section = line[7:-1] # len("#begin ") = 7 section = line[len("#begin "):]
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