Configs

class todd.configs.PyConfig[source]

Bases: SerializeMixin, Config

dumps()[source]

Reverse of loads.

Returns:

The corresponding config string.

Return type:

str

The dumped string is a readable version of the config:

>>> config = PyConfig(
...     a=1,
...     b=dict(c=3),
...     d={
...         5: 'e',
...         'f': ['g', ('h', 'i', 'j')],
...     },
...     k=[2, 1],
...     l='mn',
... )
>>> print(config.dumps())
a = 1
b = {'c': 3}
d = {5: 'e', 'f': ['g', ('h', 'i', 'j')]}
k = [2, 1]
l = 'mn'
class todd.configs.SerializeMixin[source]

Bases: Config

diff(other, html=False)[source]

Diff configs.

Parameters:
  • other (Self) – the other config to diff.

  • html (bool) – output diff in html format. Default is pure text.

Returns:

Diff message.

Return type:

str

dump(file)[source]

Dump the config to a file.

Parameters:

file (str | Path) – the file path.

Return type:

None

Refer to dumps for more details.

abstractmethod dumps()[source]
Return type:

str

classmethod load(file, **kwargs)[source]
Parameters:

file (str | Path)

Return type:

Self

classmethod loads(s, **kwargs)[source]
Parameters:

s (str)

Return type:

Self