FormatClass
exprint.formatter.FormatClass
FormatClass(class_name: str, formatter: Formatter)
Class for formatting classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Class name |
required |
Source code in exprint/formatter.py
field
field(name: str, value: Any) -> FormatClass
Adds a field to the class output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Name of the field. |
required |
|
Any
|
Value of the field. |
required |
Returns:
| Type | Description |
|---|---|
FormatClass
|
Itself |
Examples:
Source code in exprint/formatter.py
field_with
field_with(
name: str, value_fmt: Callable[[Formatter], Format]
) -> FormatClass
Adds a field to the class output. Equivalent to FormatClass.field but
formats the value using a function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Name of the field. |
required |
|
Callable[[Formatter], Format]
|
Value function. |
required |
Returns:
| Type | Description |
|---|---|
FormatClass
|
Itself |
Examples:
>>> f = Formatter()
>>> f.format_class("MyClass").field_with("foo", lambda f: f.format_any(obj.foo))