def unique ( self , name ) : # Make sure the name is valid name = self . valid ( name ) # Make sure it's not too long name = self . trim ( name ) # Now make sure it's unique unique_name = name i = 2 while unique_name in self . names : unique_name = name + str ( i ) i += 1 self . names . add ( unique_name ) return unique_name
how to make string name unique value python
Make a variable name unique by appending a number if needed .
def unique(self, name):
    """Make a variable name unique by appending a number if needed."""
    # Make sure the name is valid
    name = self.valid(name)
    # Make sure it's not too long
    name = self.trim(name)
    # Now make sure it's unique
    unique_name = name
    i = 2
    while unique_name in self.names:
      unique_name = name + str(i)
      i += 1
    self.names.add(unique_name)
    return unique_name