string_tools module¶
Pretty string utils.
- class gemseo.utils.string_tools.MessageLine(str_format, level, args, kwargs)¶
Bases:
tuple
Create new instance of MessageLine(str_format, level, args, kwargs)
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- args¶
Alias for field number 2
- kwargs¶
Alias for field number 3
- level¶
Alias for field number 1
- str_format¶
Alias for field number 0
- class gemseo.utils.string_tools.MultiLineString(lines=None)[source]¶
Bases:
object
Multi-line string lazy evaluator.
The creation of the string is postponed to when an instance is stringified through the __repr__ method. This is mainly used for logging complex strings or objects where the string evaluation cost may be avoided when the logging level dismisses a logging message.
A __add__ method is defined to allow the “+” operator between two instances, that implements the concatenation of two MultiLineString. If the other instance is not MultiLineString, it is first converted to string using its __str__ method and then added as a new line in the result.
- Parameters
lines (Iterable[MessageLine] | None) –
By default it is set to None.
- Return type
None
- add(str_format, *args, **kwargs)[source]¶
Add a line.
- Parameters
str_format (str) – The string to be process by the format() method.
args – The args passed to the format() method.
kwargs – The kwargs passed to the format() method.
*args (Any) –
**kwargs (Any) –
- Return type
None
- replace(old, new)[source]¶
Return a new MultiLineString with all occurrences of old replaced by new.
- Parameters
- Returns
The MultiLineString copy with replaced occurrences.
- Return type
- DEFAULT_LEVEL = 0¶
- INDENTATION = ' '¶
- property lines: list[gemseo.utils.string_tools.MessageLine]¶
The strings composing the lines.