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)
以上方法根据不同的需求和文件类型可以选择适合的方法进行文件拷贝。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python中字典嵌套遍历的方法是什么