1 python image copy-paste shutil
这里我使用的是python中的代码
if option2 == 1:
try:
global option2, Nimages
for sur in fm_path:
shutil.copy(sur,file1) # here how to speed up the copy function
option2 = 0
except shutil.Error as e:
print('Error: %s' % e)
Run Code Online (Sandbox Code Playgroud)
在执行此操作时.如果我复制一个冗长的文件,它需要花费太多时间来复制.有什么建议可以缩短时间吗?
如果您正在处理大尺寸的文件,您可以尝试将文件打开/写入作为副本.如快速Python文件复制中所述,默认缓冲区大小shutil.copyfileobj(执行文件复制的实际功能shutil)是16*1024,16384.您可以使用更大的缓冲区大小.
当然,
with open(src, 'rb') as fin:
with open(dst, 'wb') as fout:
shutil.copyfileobj(fin, fout, 128*1024)
Run Code Online (Sandbox Code Playgroud)