Python编码处理

  • xxx.encoding= 设置编码属性 如:request中返回 resp.encoding= 'utf-8'
  • str.encode() -----转换编码 ----操作

    # ---------------------编码处理----------------------
    str = '你好'
    # ---------------------编码操作----------------------
    str2 = str1.encode('utf-8')
    print(stre)  #byte 字节
    # ---------------------解码------------------------
    # 解码使用场景:某些函数返回值就字节码----必须解码
    str3 = str2.decode('utf-8')  #编码解码必须一致,方能正确返回

     

     

posted @ 2022-11-11 12:47  手可摘星辰/*  阅读(24)  评论(0编辑  收藏  举报