How can I save a file with the name as: oldname+"_new"+extension in an elegant way?
I currently do:
ext = os.path.splitext(file)[1]
output_file = (root+'/'+ os.path.splitext(file)[0]+"_new"+ext)
#or output_file = (os.path.join(root, os.path.splitext(file)[0])+'_new'+ext)
with open(output_file, 'w', encoding='utf-8') as file:
file.write(text)
(with the help of Python: how to retain the file extension when renaming files with os? , but not duplicate)
-- I use Python 3.12.2
filename, ext = splittext(..
but these are all trivial changes – Ladew