saferepr
Safe version of :func:repr.
def saferepr(
o: Any,
maxlen: int = None,
maxlevels: int = 3,
seen: Set = None
) - > string
Safe version of :func:repr. Warning: Make sure you set the maxlen argument, or it will be very slow for recursive objects. With the maxlen set, it's often faster than built-in repr.
Parameters
| Name | Type | Description |
|---|---|---|
| o | Any | The object to be converted into a string representation. |
| maxlen | int = None | The maximum number of characters allowed in the resulting string; essential for performance with recursive objects. |
| maxlevels | int = 3 | The maximum depth of nested structures to traverse before truncating the output. |
| seen | Set = None | A set of object IDs already processed to prevent infinite recursion in cyclic data structures. |
Returns
| Type | Description |
|---|---|
string | A string representation of the object, truncated if it exceeds the specified maximum length or recursion depth. |