[英]Is it possible to open PDF files one after other, their names are saved in a text file using Python?
[英]Combination of Content of Multiple Text files into One Text File line after the other using Python
我使用以下代碼將多個文本文件合並為一個,
import glob
read_files = glob.glob("*.txt")
with open("result.txt", "wb") as outfile:
for f in read_files:
with open(f, "rb") as infile:
outfile.write(infile.read())
我從上面的代碼收到的 output 是
2020-06-22,09:37:39,YZ-5534,72kmph,100kmph,No2020-06-22,09:38:21,CAB-3365,79kmph,100kmph,No2020-06-22,09:40: 42,ABC-5432,98kmph,100kmph,No2020-06-22,09:39:41,CB-3226,117kmph,100kmph,Yes2020-06-22,09:36:54,QX-9904,81kmph,100kmph,不
如何在每個文本文件的內容末尾引入換行符
2020-06-22,09:37:39,YZ-5534,72kmph,100kmph,無
2020-06-22,09:38:21,CAB-3365,79kmph,100kmph,無
2020-06-22,09:40:42,ABC-5432,98kmph,100kmph,無
2020-06-22,09:39:41,CB-3226,117kmph,100kmph,是的
2020-06-22,09:36:54,QX-9904,81kmph,100kmph,無
為了在連接的文本文件中獲得上述結果作為最終結果
我嘗試了上面的以下代碼行但根本不起作用
outfile.write(infile.read()+ '\n')
由於您正在閱讀文本文件,您可以試一試嗎?
import glob
read_files = glob.glob("*.txt")
with open("result.txt", "w") as outfile:
for f in read_files:
with open(f, "r") as infile:
for line in infile:
outfile.write(line)
outfile.write("\n")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.