title: How can I replace (or strip) an extension from a filename in Python?
body: <p>Is there a built-in function in Python that would replace (or remove, whatever) the extension of a filename (if it has one)?</p>
  <p>Example:</p>
  <pre><code>print replace_extension('/home/user/somefile.txt', '.jpg')
  </code></pre>
  <p>In my example: <code>/home/user/somefile.txt</code> would become <code>/home/user/somefile.jpg</code></p>
  <p>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>
  <p>I'd like something <strong>clean</strong>. Doing a simple string replacement of all occurrences of <code>.txt</code> within the string is obviously not clean. (This would fail if my filename is <code>somefile.txt.txt.txt</code>)</p>