Is there a built-in function in Python that would replace (or remove, whatever) the extension of a filename (if it has one) ?
Example:
print replace_
For Python >= 3.4:
from pathlib import Path filename = '/home/user/somefile.txt' p = Path(filename) new_filename = p.parent.joinpath(p.stem + '.jpg') # PosixPath('/home/user/somefile.jpg') new_filename_str = str(new_filename) # '/home/user/somefile.jpg'