Fix Python – How can I replace (or strip) an extension from a filename in Python?

Is there a built-in function in Python that would replace (or remove, whatever) the extension of a filename (if it has one)?
print replace_extension(‘/home/user/somefile.txt’, ‘.jpg’)

In my example: /home/user/somefile.txt would become /home/user/somefile.jpg
I don’t know if it matters, but I need this for a SCons module I’m writing. (So….

Fix Python – Split by comma and strip whitespace in Python

I have some python code that splits on comma, but doesn’t strip the whitespace:
>>> string = “blah, lots , of , spaces, here ”
>>> mylist = string.split(‘,’)
>>> print mylist
[‘blah’, ‘ lots ‘, ‘ of ‘, ‘ spaces’, ‘ here ‘]

I would rather end up with whitespace removed like this:
[‘blah’, ‘lots’, ‘of’, ‘spaces’, ‘here’]

I am aware that I co….