gpt4 book ai didi

Python 按给定顺序将多个文件 append 到一个大文件

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:17 24 4
gpt4 key购买 nike

我有多达 8 个独立的 Python 进程在共享文件夹中创建临时文件。然后我希望控制进程将所有临时文件按一定顺序 append 到一个大文件中。在与操作系统无关的 shell 级别执行此操作的最快方法是什么?

最佳答案

仅使用简单的文件 IO:

# tempfiles is a list of file handles to your temp files. Order them however you like
f = open("bigfile.txt", "w")
for tempfile in tempfiles:
f.write(tempfile.read())

这与操作系统无关。它也相当简单,并且性能应该与使用其他任何东西一样好。

关于Python 按给定顺序将多个文件 append 到一个大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55112862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com