(data=None)
return array.array('B', data)
Convert loosely specified `data` to a byte array.

    The following types of `data` are supported:

    - the `None` value (returns an new empty array);
    - an `array('B')` value (no-op, returns it back);
    - lists or iterables of small enough integers;
    - strings.
Convert loosely specified `data` to a byte array.
Convert loosely specified data to a byte array .
def as_array(data=None):
    """Convert loosely specified `data` to a byte array.

    The following types of `data` are supported:

    - the `None` value (returns an new empty array);
    - an `array('B')` value (no-op, returns it back);
    - lists or iterables of small enough integers;
    - strings.
    """

    if data is None:
        return array.array('B')

    if isinstance(data, array.array) and data.typecode == 'B':
        return data

    if isinstance(data, str):
        return array.array('B', data.encode('utf-8'))

    return array.array('B', data)
def as_array ( data = None ) : if data is None : return array . array ( 'B' ) if isinstance ( data , array . array ) and data . typecode == 'B' : return data if isinstance ( data , str ) : return array . array ( 'B' , data . encode ( 'utf-8' ) ) return array . array ( 'B' , data )