最简单的方法可能就是忘掉行,只读取整个文件,然后将其写入输出:
with open('command.fort.13', 'wb') as outFile: with open('command.info', 'rb') as com, open('fort.13', 'rb') as fort13: outFile.write(com.read()) outFile.write(fort13.read())
正如评论中指出的那样,如果两个输入中的任何一个输入较大(因为它将首先将整个文件复制到内存中),这可能会导致大量的内存使用。如果这可能是一个问题,那么以下 *** 作也将同样有效(通过分块复制输入文件):
import shutilwith open('command.fort.13', 'wb') as outFile: with open('command.info', 'rb') as com, open('fort.13', 'rb') as fort13: shutil.copyfileobj(com, outFile) shutil.copyfileobj(fort13, outFile)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)