Python拷貝文件的方法有以下幾種:
import shutil
shutil.copy(source, destination)
import shutil
shutil.copy2(source, destination)
import shutil
shutil.copyfile(source, destination)
import os
with open(source, 'rb') as fsrc, open(destination, 'wb') as fdst:
for line in fsrc:
fdst.write(line)
import os
with open(source, 'rb') as fsrc, open(destination, 'wb') as fdst:
fdst.write(fsrc.read())
import shutil
shutil.copytree(source, destination)
以上方法根據(jù)不同的需求和文件類(lèi)型可以選擇適合的方法進(jìn)行文件拷貝。