Helpful Utils

starstar.kw2id(kw, *keys, key=True, sep='-', key_sep='_', filter=True, missing='', format=<class 'str'>)[source]

Create an id from keyword arguments.

Parameters:
  • kw (dict) – The available arguments.

  • *keys (str) – The keys to use.

  • key (bool) – Include the key in the id?

  • sep (str) – The separator between each item.

  • key_sep (str) – The separator between key and value (if key=True).

  • filter (bool) – Filter out missing values.

  • format (callable) – A function that formats the values.

kw = {'name': 'asdf', 'count': 10, 'enabled': True}
assert starstar.kw2id(kw, 'name', 'count', 'enabled', 'xxx') == 'name_asdf-count_10-enabled_True'
assert starstar.kw2id(kw, 'name', 'xxx', 'count', filter=False) == 'name_asdf-xxx_-count_10'
starstar.asitems(x, types=(<class 'list'>, <class 'tuple'>, <class 'set'>))[source]

Convert a value into a list/tuple/set. Useful for arguments that can be None, single item, list, tuple.

assert starstar.asitems(None) == []
assert starstar.asitems('asdf') == ['asdf']
assert starstar.asitems([1, 2, 3]) == [1, 2, 3]