(s, encoding='utf-8')
return s
Ensure that s is converted to bytes from the encoding.
Ensure that s is converted to bytes from the encoding.
Ensure that s is converted to bytes from the encoding .
def to_bytes(s, encoding='utf-8'):
    """Ensure that s is converted to bytes from the encoding."""
    if hasattr(s, 'encode') and not isinstance(s, bytes):
        s = s.encode(encoding)
    return s
def to_bytes ( s , encoding = 'utf-8' ) : if hasattr ( s , 'encode' ) and not isinstance ( s , bytes ) : s = s . encode ( encoding ) return s