說我有一個文本文件像這樣的東西:添加「 n」來指定行在文本
Områder dorsalt i overgangssonen, midtre tredjedel med blodpunkter.R: Malignitet ikke påvist
我怎麼能在文本中的每個R:
前添加\n
幾個文件? 這是我的代碼至今:
import os
for root, dirs, files in os.walk(".", topdown=True):
for name in files:
if name != "merge_reports_into_metadata_csv.py" or name != "BakgrunnsData_v2.csv" or name != "remove_text_windows.py":
slash = "\\"
if root == ".":
slash = ""
f = open(root.strip(".").strip("\\") + slash + name, "r")
lines = f.readlines()
f.close()
f = open(root.strip(".").strip("\\") + slash + name, "w")
for line in lines:
if line != "R:" + "\n":
f.write(line)
else:
print("adding line space the word 'R:' from " + name)
f.close()
print("all 'R:'s are moved one line down")