def cleanpath(path):
 items = path.split('.')
 if (len(items) > 1):
  path = re.sub('[^\\w\\.]+', '_', (('_'.join(items[:(-1)]) + '.') + ''.join(items[(-1):])))
 else:
  path = re.sub('[^\\w\\.]+', '_', ''.join(items[(-1):]))
 return path

def cleanpath ( path ) : items = path . split ( '.' ) if ( len ( items ) > 1 ) : path = re . sub ( '[^\\w\\.]+' , '_' , ( ( '_' . join ( items [ : ( - 1 ) ] ) + '.' ) + '' . join ( items [ ( - 1 ) : ] ) ) ) else : path = re . sub ( '[^\\w\\.]+' , '_' , '' . join ( items [ ( - 1 ) : ] ) ) return path
turns any expression/path into a valid filename .