答案 0 :(得分:0)
尝试os.path.splitext()
,它返回文件名的开头,文件扩展名作为元组的第一个和第二个元素。
示例:
import os
f = "mymusic.wav"
filename,ext = os.path.splitext(f) # save the file extension
# filename = "mymusic"; ext = ".wav"
filename = filename + "_new"
os.rename(f, filename+ext) # generate new filename with same extension