- rename() is a operating system function in python which are able to rename the files and directories
Syntax-
os.rename(oldfilename,newfilename)
program-
import os
f=open('oldfile.txt','r')
print(f.read())
f.close()
os.rename('oldfile.txt','newfile.txt')
This is the file
f=open('newfile.txt','r')
print(f.read())
f.close()
This is the file
f=open('newfile.txt','r')
print(f.read())
f.close()
f=open('oldfile.txt','r')
FileNotFoundError: [Errno 2] No such file or directory: 'oldfile.txt'