def parse_float_value_from_text_stream(text, key):
"""Parse float value from the text.
Go through all lines of the text file, find the line with given key
and parse float value specified here.
"""
regexp = key + "\s*=\s*(\d.\d*)"
for line in text.split("\n"):
if line.startswith(key):
# the key was found, now try to find and parse the float value
match = re.fullmatch(regexp, line)
assert match is not None
assert match.lastindex == 1
return float(match.group(1))
parsing.py 文件源码
python
阅读 35
收藏 0
点赞 0
评论 0
评论列表
文章目录