【问题标题】:I use chardet to test encode , but i got error我使用 chardet 测试编码,但出现错误
【发布时间】:2018-05-17 02:54:14
【问题描述】:
import chardet 
a='haha'
print(chardet.detect(a))

TypeError: 类型为字节或字节数组的预期对象,得到:

我只是输入教程中的代码。 实在想不通到底出了什么问题。

【问题讨论】:

  • 没有被编码。

标签: python python-3.x chardet


【解决方案1】:

要将字符串转换为字节...

变化:

a = 'haha'

收件人:

a = b'haha'

【讨论】:

    【解决方案2】:

    你也可以使用

    a='haha'
    print(chardet.detect(a.encode()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 2022-09-23
      • 2021-04-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      相关资源
      最近更新 更多