在Python中复制文件,你可以使用`shutil`模块中的几个函数,具体如下:
1. 使用`shutil.copy()`函数:
```python
import shutil
src = 'path/to/source/file.txt'
dst = 'path/to/destination/file.txt'
shutil.copy(src, dst)
2. 使用`shutil.copy2()`函数,该函数会尝试复制文件的元数据(如权限):```pythonimport shutil
src = 'path/to/source/file.txt'
dst = 'path/to/destination/file.txt'
shutil.copy2(src, dst)

3. 使用`shutil.copyfile()`函数,该函数直接复制文件内容而不考虑文件元数据:
```python
import shutil
src = 'path/to/source/file.txt'
dst = 'path/to/destination/file.txt'
shutil.copyfile(src, dst)
4. 使用`shutil.copytree()`函数复制整个目录及其内容:```pythonimport shutil
src = 'path/to/source/directory'
dst = 'path/to/destination/directory'
shutil.copytree(src, dst)
