def u2b ( string ) : if ( ( PY2 and isinstance ( string , unicode ) ) or ( ( not PY2 ) and isinstance ( string , str ) ) ) : return string . encode ( 'utf-8' ) return string
python str to bytes python2
unicode to bytes
def u2b(string):
    """ unicode to bytes"""
    if ((PY2 and isinstance(string, unicode)) or
        ((not PY2) and isinstance(string, str))):
        return string.encode('utf-8')
    return string