TypeError: a bytes-like object is required, not 'str'


 python bytes和str两种类型转换的函数encode(),decode()

  • str通过encode()方法可以编码为指定的bytes
  • 反过来,如果我们从网络或磁盘上读取了字节流,那么读到的数据就是bytes。要把bytes变为str,就需要用decode()方法

例如:

date=“12345”  #str类型

date.encode()  #转换为bytes类型

posted @ 2018-03-12 15:15  溪棱  阅读(431)  评论(0编辑  收藏  举报