brainstate.util.pretty_repr

Contents

brainstate.util.pretty_repr#

brainstate.util.pretty_repr(x, indent=2)[source]#

Create a pretty string representation.

Parameters:
  • x (Any) – Object to represent. If a dict or FrozenDict, will be pretty-printed with indentation. Otherwise, returns repr(x).

  • indent (int) – Number of spaces per indentation level (default 2).

Returns:

A formatted string representation.

Return type:

str

See also

FrozenDict.pretty_repr

Pretty representation for FrozenDict.

Examples

>>> from brainstate.util import pretty_repr

>>> d = {'a': 1, 'b': {'c': 2, 'd': 3}}
>>> print(pretty_repr(d))
{
  'a': 1,
  'b': {
    'c': 2,
    'd': 3
  }
}

>>> # Non-dict objects return normal repr
>>> pretty_repr([1, 2, 3])
'[1, 2, 3]'