force_str
Similar to smart_str(), except that lazy instances are resolved to strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
def force_str(
s: any,
encoding: string = "utf-8",
strings_only: boolean = false,
errors: string = "strict"
) - > string
Similar to smart_str(), except that lazy instances are resolved to strings, rather than kept as lazy objects. If strings_only is True, don't convert (some) non-string-like objects.
Parameters
| Name | Type | Description |
|---|---|---|
| s | any | The input object to be converted into a string. |
| encoding | string = "utf-8" | The character encoding to use when decoding byte strings. |
| strings_only | boolean = false | If True, prevents the conversion of non-string-like objects such as integers, floats, or None. |
| errors | string = "strict" | The error handling scheme to use for decoding errors (e.g., 'strict', 'ignore', 'replace'). |
Returns
| Type | Description |
|---|---|
string | The resulting string after conversion and decoding, or the original object if strings_only is enabled and the type is protected. |