parameters: (name: str)
return_statement: return name
docstring: Create valid Python identifiers from any string.
  
      Check if name contains any special characters. If it contains any
      special characters, the special characters will be replaced by
      a special string and a prefix is added.
  
      Raises
      ------
      SyntaxError
          If the returned name is not a Python valid identifier, raise an exception.
          This can happen if there is a hashtag in the name, as the tokenizer will
          than terminate and not find the backtick.
          But also for characters that fall out of the range of (U+0001..U+007F).
docstring_summary: Create valid Python identifiers from any string.
docstring_tokens: Create valid Python identifiers from any string .
function: def create_valid_python_identifier(name: str) -> str:
      """
      Create valid Python identifiers from any string.
  
      Check if name contains any special characters. If it contains any
      special characters, the special characters will be replaced by
      a special string and a prefix is added.
  
      Raises
      ------
      SyntaxError
          If the returned name is not a Python valid identifier, raise an exception.
          This can happen if there is a hashtag in the name, as the tokenizer will
          than terminate and not find the backtick.
          But also for characters that fall out of the range of (U+0001..U+007F).
      """
      if name.isidentifier() and not iskeyword(name):
          return name
  
      # Create a dict with the special characters and their replacement string.
      # EXACT_TOKEN_TYPES contains these special characters
      # token.tok_name contains a readable description of the replacement string.
      special_characters_replacements = {
          char: f"_{token.tok_name[tokval]}_"
          for char, tokval in (tokenize.EXACT_TOKEN_TYPES.items())
      }
      special_characters_replacements.update(
          {
              " ": "_",
              "?": "_QUESTIONMARK_",
              "!": "_EXCLAMATIONMARK_",
              "$": "_DOLLARSIGN_",
              "€": "_EUROSIGN_",
              # Including quotes works, but there are exceptions.
              "'": "_SINGLEQUOTE_",
              '"': "_DOUBLEQUOTE_",
              # Currently not possible. Terminates parser and won't find backtick.
              # "#": "_HASH_",
          }
      )
  
      name = "".join(special_characters_replacements.get(char, char) for char in name)
      name = "BACKTICK_QUOTED_STRING_" + name
  
      if not name.isidentifier():
          raise SyntaxError(f"Could not convert '{name}' to a valid Python identifier.")
  
      return name
function_tokens: def create_valid_python_identifier ( name : str ) -> str : if name . isidentifier ( ) and not iskeyword ( name ) : return name # Create a dict with the special characters and their replacement string. # EXACT_TOKEN_TYPES contains these special characters # token.tok_name contains a readable description of the replacement string. special_characters_replacements = { char : f"_{token.tok_name[tokval]}_" for char , tokval in ( tokenize . EXACT_TOKEN_TYPES . items ( ) ) } special_characters_replacements . update ( { " " : "_" , "?" : "_QUESTIONMARK_" , "!" : "_EXCLAMATIONMARK_" , "$" : "_DOLLARSIGN_" , "€":  " EUROSIGN_", # Including quotes works, but there are exceptions. "'" : "_SINGLEQUOTE_" , '"' : "_DOUBLEQUOTE_" , # Currently not possible. Terminates parser and won't find backtick. # "#": "_HASH_", } ) name = "" . join ( special_characters_replacements . get ( char , char ) for char in name ) name = "BACKTICK_QUOTED_STRING_" + name if not name . isidentifier ( ) : raise SyntaxError ( f"Could not convert '{name}' to a valid Python identifier." ) return name