string_tools module¶
Pretty string utils¶
Classes:
|
Create new instance of MessageLine(str_format, level, args, kwargs) |
|
Multi-line string lazy evaluator. |
Functions:
|
String representation of an object. |
- class gemseo.utils.string_tools.MessageLine(str_format, level, args, kwargs)¶
Bases:
tuple
Create new instance of MessageLine(str_format, level, args, kwargs)
Attributes:
Alias for field number 2
Alias for field number 3
Alias for field number 1
Alias for field number 0
Methods:
count
(value, /)Return number of occurrences of value.
index
(value[, start, stop])Return first index of value.
- args¶
Alias for field number 2
- 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.
- 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.
Attributes:
The strings composing the lines.
Methods:
add
(str_format, *args, **kwargs)Add a line.
dedent
()Decrease the indentation.
indent
()Increase the indentation.
offset
()replace
(old, new)Return a new MultiLineString with all occurrences of old replaced by new.
reset
()Reset the indentation.
- Parameters
lines (Optional[Iterable[MessageLine]]) –
By default it is set to None.
- Return type
None
- DEFAULT_LEVEL = 0¶
- INDENTATION = ' '¶
- 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
- property lines¶
The strings composing the lines.