WrightTools.kit.string2identifier

WrightTools.kit.string2identifier(s, replace=None)[source]

Turn a string into a valid python identifier.

This method restricts identifier characters to ASCII letters, numbers, and underscore. The characters are slightly more restrictive than python 3 itself, and may be refactored in future (see PEP 3131).

For non-valid characters, the default replacement is “_”. Replacement assignments can be customized with the replace kwarg.

Parameters:
  • s (string) – string to convert

  • replace (dictionary[str, str] (optional)) – dictionary of characters (keys) and their replacements (values). Values should be ASCII or underscore. Unspecified non-ascii characters are converted to underscore.

Returns:

valid python identifier.

Return type:

str