在Python中,你可以使用`shutil`模块来拷贝文件。以下是使用`shutil`模块进行文件拷贝的几种方法:
1. 使用`shutil.copy()`函数:
import shutil
shutil.copy('source.txt', 'destination.txt')
2. 使用`shutil.copy2()`函数,该函数会尝试保持文件的元数据(如时间戳):
import shutil
shutil.copy2('source.txt', 'destination.txt')
3. 使用`shutil.copyfile()`函数,该函数直接复制文件内容,不会创建目标文件如果它不存在:
import shutil
shutil.copyfile('source.txt', 'destination.txt')
4. 使用`shutil.copytree()`函数来复制整个目录及其内容:
import shutil
shutil.copytree('source_dir', 'destination_dir')
请根据你的具体需求选择合适的方法。