我有一个results.txt
文件看起来像这样:
的Python:替换功能来编辑文件
[["12 - 22 - 30 - 31 - 34 - 39 - 36"],
["13 - 21 - 28 - 37 - 39 - 45 - 6"],
["2 - 22 - 32 - 33 - 37 - 45 - 11"],
["3 - 5 - 11 - 16 - 41 - 48 - 32"],
["2 - 3 - 14 - 29 - 35 - 42 12"],
["14 - 30 - 31 - 36 - 44 - 47 26"]]
我想更换“ - ”与RESULTS.TXT文件“‘’”所以它看起来像一个Python列表。
我尝试使用下面的代码,但输出长相酷似RESULTS.TXT
output = open("results2.txt", 'w')
f = open("results.txt", 'r')
read = f.readlines()
for i in read:
i.replace(" - ",'","')
output.write(i)