Hi,
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_extension('/home/user/somefile.txt', '.jpg')
In my example: /home/user/somefile.txt
would become /home/user/somefile.jpg
Sorry if my question is really trivial, but I'm learning Python for 2 hours now and I didn't found a way to do this in the official docs or even on Google.
Thanks.
P.S: I don't know if it matters, but I need this for a SCons module I'm writing. (So perhaps there is some SCons specific function I can use ?)
P.S2: I'd like something clean. Doing a simple string replacement of all occurrences of .txt
within the string is obviously not clean. (This would fail if my filename is somefile.txt.txt.txt
)