def unique_file_name(base_name, extension=''):
 idcount = 0
 if (extension and (not extension.startswith('.'))):
  extension = ('.%s' % extension)
 fname = (base_name + extension)
 while os.path.exists(fname):
  fname = ('%s-%d%s' % (base_name, idcount, extension))
  idcount += 1
 return fname

def unique_file_name ( base_name , extension = '' ) : idcount = 0 if ( extension and ( not extension . startswith ( '.' ) ) ) : extension = ( '.%s' % extension ) fname = ( base_name + extension ) while os . path . exists ( fname ) : fname = ( '%s-%d%s' % ( base_name , idcount , extension ) ) idcount += 1 return fname
creates a unique file name based on the specified base name .