【发布时间】:2018-07-10 02:04:12
【问题描述】:
嘿 stackoverflow 我需要帮助解决这个问题。我希望能够读取格式如下的文本文件:
test: value1
test2: value2
test3(sometimes included): value3
test: value1
test2: value2
test: value1
test2: value2
test3(sometimes included): value3
您会看到 test3 有时包含在文件中,我希望能够读取它,但不希望它与文件中的其他值混淆。
为了完全清楚,我希望能够在 python 中读取文件并将变量的值放入 python 中的字符串中。
这是我目前所拥有的(这不是我想要的,因为如果该行没有 test3,它会与其他值混淆)
file = open("output.txt").readlines()
with line in file:
if "test3" in line:
test = find_between(...)
test2 = find_between(...)
test3 = find_between(...)
...
【问题讨论】:
标签: python python-2.7 file text