【码】Python3 bytes解码为str
in 代码片段 with 0 comment

【码】Python3 bytes解码为str

in 代码片段 with 0 comment

代码来源:Github@Chyroc
说明:Python3去除了字符串的encode函数所以用这个方法来转换

def bytes_decode(b):
    if isinstance(b, dict):
        dict_new = dict()
        for k, v in b.items():
            dict_new[bytes_decode(k)] = bytes_decode(v)
        return dict_new
    elif isinstance(b, list):
        list_new = list()
        for b_single in b:
            list_new.append(bytes_decode(b_single))
        return list_new
    elif isinstance(b, bytes):
        return b.decode()
    else:
        return b
Comments are closed.