want_bytes
Python API reference for the function encoding.want_bytes.
Public API
Function: want_bytes
Canonical path: encoding.want_bytes
Declared in: encoding.py
Signature
def want_bytes(s, encoding="utf-8", errors="strict"): ...
Summary
Ensures that the input is returned as bytes.
Behavior
If the input is a string, it is encoded using the specified encoding and error handling strategy.
Parameters
- s: The input string or bytes to ensure is in byte format.
- encoding: The encoding to use if the input is a string, defaulting to utf-8.
- errors: The error handling scheme to use during encoding, defaulting to strict.
Returns
- Return value 1: The input converted to bytes if it was a string, otherwise the original input.