force_bytes
Similar to smart_bytes, 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_bytes(
s: Any,
encoding: string = "utf-8",
strings_only: boolean = false,
errors: string = "strict"
) - > bytes
Similar to smart_bytes, 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 value to be converted into bytes, such as a string, memoryview, or lazy object. |
| encoding | string = "utf-8" | The character encoding to use when converting strings to bytes. |
| strings_only | boolean = false | When True, prevents the conversion of non-string-like objects (such as integers or None) to bytes. |
| errors | string = "strict" | The error handling scheme to use for encoding and decoding errors. |
Returns
| Type | Description |
|---|---|
bytes | The byte-string representation of the input value, encoded according to the specified encoding. |