我的文件是txt格式的,我编写了一个简短的代码,将这三个文件合并为一个文件。输入文件为(1)18.8MB,超过16K列;(2)18.8MB,超过16K列;(3)10.5MB,超过7K列。代码可以工作,但是它只合并前两个文件并创建输出文件。不包括来自第三个输入文件的数据。这里有什么问题?txt文件的大小有限制吗?你知道吗
filenames = ['/Users/icalic/Desktop/chr_1/out_chr1_firstset.txt', '/Users/icalic/Desktop/chr_1/out_chr1_secondset.txt', '/Users/icalic/Desktop/chr_1/out_chr1_thirdset.txt']
with open('/Users/icalic/Desktop/chr1_allfinal.txt', 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
for line in infile:
outfile.write(line)
只需使用标准库中的^{} :
如果您需要更好地控制内存使用或需要处理二进制文件,请使用
shutil.copyfileobj
:相关问题 更多 >
编程相关推荐