Task: there is a file with the .raw extension in the folder and I need to rename this file to the same one, but with a different .txt extension – how can I do this?
You need to import the
os module, which has the
os.rename() methods. Using the
os.path.splitext() method, you can split the source file into two parts – its name and permission, which falls into square brackets as  – name and  – permission. Next, you just need to glue the name with the new permission via
#Переименовать файл из .raw в .txt import os file="C:/Users/Vasya/Documents/Python/tangaria/scores.raw" filename = os.path.splitext(file) os.rename(file, filename + ".txt")