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_
Another way to do is to use the str.rpartition(sep) method.
For example:
filename = '/home/user/somefile.txt' (prefix, sep, suffix) = filename.rpartition('.') new_filename = prefix + '.jpg' print new_filename