def replace_extension(filename, new_extension):
 if (isinstance(filename, (str, unicode)) and (u'.' in filename)):
  (basename, _, _) = filename.rpartition(u'.')
  if basename:
   return u'{0}.{1}'.format(basename, new_extension)
 return filename

def replace_extension ( filename , new_extension ) : if ( isinstance ( filename , ( str , unicode ) ) and ( u'.' in filename ) ) : ( basename , _ , _ ) = filename . rpartition ( u'.' ) if basename : return u'{0}.{1}' . format ( basename , new_extension ) return filename
replace the extension of the provided filename with a new extension .