我有 3 个文件1.txt
, 2.txt
,3.txt
并且我正在尝试将这些文件的内容连接到 Python 中的一个输出文件中。谁能解释一下为什么下面的代码只写了1.txt
and 而不是2.txt
or的内容3.txt
?我确定这很简单,但我似乎无法找出问题所在。
import glob
import shutil
for my_file in glob.iglob('/Users/me/Desktop/*.txt'):
with open('concat_file.txt', "w") as concat_file:
shutil.copyfileobj(open(my_file, "r"), concat_file)
谢谢您的帮助!