agglovar.util.str

String utility functions.

Functions

collision_rename(→ str)

Rename a variable to avoid collisions with existing values.

collision_rename_all(→ collections.abc.Iterator[str])

Iterate through a list of names and deduplicate.

Module Contents

agglovar.util.str.collision_rename(var_name: str, separator: str | None = '.', *args: collections.abc.Container[str]) str

Rename a variable to avoid collisions with existing values.

Adds “_n” to a variable name where “n” is the lowest integer that does not collide with an existing name. If var_name does not collide, it is returned unmodified.

Parameters:
  • var_name – Variable name.

  • separator – Separator to use between the variable name and the counter. If None, defaults to “.”.

  • args – One or more containers to search for matches.

Returns:

Renamed string.

agglovar.util.str.collision_rename_all(var_names: collections.abc.Iterable[str], separator: str | None = '.', *args: collections.abc.Container[str]) collections.abc.Iterator[str]

Iterate through a list of names and deduplicate.

Parameters:
  • var_names – Iterator of names.

  • separator – Separator to use between the variable name and the counter. If None, defaults to “.”.

  • args – One or more containers to search for matches.

Returns:

An iterator of deduplicated names.