字符串我有以下格式的文本文件:前面加上行號在Python
"This is record #1"
"This is record #2"
"This is record #3"
我需要在以下格式的輸出:
Line number (1) --\t-- "This is Record # 1"
2-- \t-- "This is Record # 2"
3-- \t-- "This is Record # 3"
當前代碼:
f = open("C:\input.txt","r")
write_file = open("C:\output.txt","r+")
while True:
line = f.readline()
write_file.write(line)
if not line : break
write_file.close()
f.close()
順便說一句,這將是_prepending_的行號。 –
我很抱歉把它寫錯了。 – user3339672