infile = open("data.txt","r")
outfile = open("Excel.csv","w")
while True:
name = infile.readline().strip()
address = infile.readline().strip()
number = infile.readline().strip()
data = ','.join([name,address,number])
if data == ",,":
break
data += '\n'
outfile.write(data)
with open("input.txt", "r") as infile:
line = infile.read().split()
line = [" ".join(line[i:i+3]) for i in range(0,len(line),3)]
print(line)
with open("output.txt", "w") as outfile:
for i in line:
outfile.write(i + "\n")
这应该做到:
如果我记得我在Excel的时候,CSV做得很好
你可以用
Microsoft word
来做将数据粘贴到MSWord中(作为
keep text only
),然后将它们全部选中(Ctrl+A
)。转到insert
功能区。从Table
按钮,选择convert text to table
选择
number of columns
3并选择separate text at
作为Paragraph
它会给你确切的输出你想要的。不需要对你遇到的每件事都进行编码。您可以阅读更多关于它的信息here
你可能想要这样的东西:
output.txt
的内容:相关问题 更多 >
编程相关推荐