smart_bytes
Return a bytestring version of 's', encoded as specified in 'encoding'.
If strings_only is True, don't convert (some) non-string-like objects.
def smart_bytes(
s: Any,
encoding: string = "utf-8",
strings_only: boolean = false,
errors: string = "strict"
) - > bytes
Return a bytestring version of 's', encoded as specified in 'encoding'. If strings_only is True, don't convert (some) non-string-like objects.
Parameters
| Name | Type | Description |
|---|---|---|
| s | Any | The input value to be converted into a bytestring. |
| encoding | string = "utf-8" | The character encoding to use for the conversion process. |
| strings_only | boolean = false | If True, prevents the conversion of non-string-like objects to ensure only text-based data is processed. |
| errors | string = "strict" | The error handling scheme to use for encoding errors, such as 'strict', 'ignore', or 'replace'. |
Returns
| Type | Description |
|---|---|
bytes | The encoded bytestring version of the input, or the original object if it is a lazy translation promise. |