giả sử chúng ta có nhiều tập tin văn bản như sau:kết hợp nhiều file văn bản vào một file văn bản sử dụng python
file1:
abc
def
ghi
file2:
ABC
DEF
GHI
file3:
adfafa
tệp4:
ewrtwe
rewrt
wer
wrwe
Làm sao chúng ta có thể làm cho một tập tin văn bản như dưới đây:
kết quả:
abc
def
ghi
ABC
DEF
GHI
adfafa
ewrtwe
rewrt
wer
wrwe
đang liên quan có thể là:
import csv
import glob
files = glob.glob('*.txt')
for file in files:
with open('result.txt', 'w') as result:
result.write(str(file)+'\n')
Sau này? Bất kỳ giúp đỡ?
chủ đề này là một ducplicate của http://stackoverflow.com/questions/13613336/python-concatenate-text-files – sancelot