2016-11-01 25 views

回答

0

您可以使用glob爲您提供文件列表,例如*.txt*.*,然後按如下方式在一個循環中進行讀/寫:

import glob 

output = 'merged.txt' 

with open(output, 'w') as f_merged: 
    for filename in glob.glob('*.*'): 
     if filename != output: 
      with open(filename) as f_input: 
       f_merged.writelines(f_input) 
相關問題