os.replace(old, new) 将文件�命�。
首先创建两个文件:- 1.txt 内容是1
- 2.txt 内容是2
import OS
os.replace('1.txt', '2.txt')
执行��现�剩下一个:2.txt,但内容是 1。
所以 os.replace(file1,file2) 这个函数相当于用 file2 ç»™ file1 é‡�命å��ï¼Œå¹¶åˆ é™¤ file2。