如何使用 python 将大文件从源文件分块复制到目标文件?

How do I copy a large file in chunks from a source file to a destination file using python?

文件可以说是20GB。导入、读取文件然后写入另一个文件的传统方法是不可行的。

shutil 模块具有为此目的设计的功能:

import shutil
shutil.copy(src, dst)

对于类文件对象(缓冲区、请求主体等),您可以使用 shutil.copyfileobj

with open('path/to/dest.file', 'wb') as dst:
    shutil.copyfileobj(source_file_like_object, dst)