(x)
return x.encode('utf-8')
Convert the given string to :class:`bytes` if necessary.

    If the argument is already :class:`bytes`, it is returned unchanged; if it is :class:`str`, it is encoded as UTF-8.
Convert the given string to :class:`bytes` if necessary.
Convert the given string to : class : bytes if necessary .
def ensure_bytes(x):
    """Convert the given string to :class:`bytes` if necessary.

    If the argument is already :class:`bytes`, it is returned unchanged; if it is :class:`str`, it is encoded as UTF-8.
    """

    if isinstance(x, bytes):
        return x
    # "All char * in the runtime API should be considered to have UTF-8 encoding."
    # https://developer.apple.com/documentation/objectivec/objective_c_runtime?preferredLanguage=occ
    return x.encode('utf-8')
def ensure_bytes ( x ) : if isinstance ( x , bytes ) : return x # "All char * in the runtime API should be considered to have UTF-8 encoding." # https://developer.apple.com/documentation/objectivec/objective_c_runtime?preferredLanguage=occ return x . encode ( 'utf-8' )