FormatDict
exprint.formatter.FormatDict
FormatDict(formatter: Formatter)
Class for formatting dictionary of items.
Source code in exprint/formatter.py
item
item(key: Any, value: Any) -> FormatDict
Adds a pair of key-value to the dictionary output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Key to add. |
required |
|
Any
|
Value to add. |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
Source code in exprint/formatter.py
items
items(values: Iterable[tuple[Any, Any]]) -> FormatDict
Adds all pairs of key-values to the dictionary output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[tuple[Any, Any]]
|
Pair of key-values |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
Source code in exprint/formatter.py
key
key(key: Any) -> FormatDict
Adds a key to the dictionary output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Key to add. |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
Source code in exprint/formatter.py
key_with
key_with(
key_fmt: Callable[[Formatter], Format],
) -> FormatDict
Adds a key to the dictionary output. Equivalent to FormatDict.key but
formats the value using a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[Formatter], Format]
|
Key function. |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
>>> f = Formatter()
>>> key = list(map.keys())[0]
>>> f.format_dict().key_with(lambda f: f.format_any(key))
Source code in exprint/formatter.py
value
value(value: Any) -> FormatDict
Adds a value to the dictionary output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Value to add. |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
Source code in exprint/formatter.py
value_with
value_with(
value_fmt: Callable[[Formatter], Format],
) -> FormatDict
Adds a value to the dictionary output. Equivalent to FormatDict.value
but formats the value using a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[Formatter], Format]
|
Value function. |
required |
Returns:
| Type | Description |
|---|---|
FormatDict
|
Itself |
Examples:
>>> f = Formatter()
>>> value = list(map.values())[0]
>>> f.format_dict().value_with(lambda f: f.format_any(value))