3
import chardet 
a='haha'
print(chardet.detect(a))

TypeError:预期的字节或字节数组类型的对象,得到:< class 'str'>

我只是从教程中输入代码。我真的无法弄清楚发生了什么错误。

4

2 回答 2

6

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

改变:

a = 'haha'

到:

a = b'haha'
于 2018-05-17T04:49:54.907 回答
2

你也可以使用

a='haha'
print(chardet.detect(a.encode()))
于 2020-07-15T02:19:06.200 回答