Skip to main content

smart_str

Return a string representing 's'. Treat bytestrings using the 'encoding' codec.

If strings_only is True, don't convert (some) non-string-like objects.

def smart_str(
s: any,
encoding: string = "utf-8",
strings_only: boolean = false,
errors: string = "strict"
) - > string

Return a string representing 's'. Treat bytestrings using the 'encoding' codec. If strings_only is True, don't convert (some) non-string-like objects.

Parameters

NameTypeDescription
sanyThe object to be converted into a string representation.
encodingstring = "utf-8"The codec used to decode the input if it is a bytestring.
strings_onlyboolean = falseIf True, prevents the conversion of non-string-like objects such as integers or booleans.
errorsstring = "strict"The error handling scheme to use for decoding errors (e.g., 'strict', 'ignore', 'replace').

Returns

TypeDescription
stringThe string representation of the input, or the original object if strings_only is enabled and the input is a non-string-like type.