import chardet
a='haha'
print(chardet.detect(a))
TypeError: Expected object of type bytes or bytearray, got: < class 'str'>
I just type code from tutorial. I really can not figure out what wrong happended.
import chardet
a='haha'
print(chardet.detect(a))
TypeError: Expected object of type bytes or bytearray, got: < class 'str'>
I just type code from tutorial. I really can not figure out what wrong happended.
To convert a string to a byte...
Change:
a = 'haha'
To:
a = b'haha'
You can also use
a='haha'
print(chardet.detect(a.encode()))
© 2022 - 2024 — McMap. All rights reserved.