eg: input TXT file
akey=avalue1,
avalue2,
avalue3
bkey=cvalue
这里的输出我想在一个列表中,它的两个元素将是
[akey=avalue1,avalue2,avalue3
bkey=cvalue]
使用几个regexp并不难:
import re
data = """
akey=avalue1,
avalue2,
avalue3
bkey=cvalue
""".strip()
# Fold comma-newline-spaces to a single comma
data = re.sub(r",ns*", ",", data)
# Fold multiple newlines to one
data = re.sub(r"n+", "n", data)
print(data)
这个输出
akey=avalue1,avalue2,avalue3
bkey=cvalue