Added mpdehaan suggestion to use os.path.splitext. Wise suggestion, does look clearner