是否有一个Python库可以检测(并可能解码)字符串的编码?
我找到chardet但它给了我一个错误,使用:
chardet.detect(self.ui.TextFrom.toPlainText())
got: = chardet.detect(self.ui.TextFrom.toPlainText())
File .... u.feed(aBuf) File ....
if self._highBitDetector.search(aBuf):
TypeError: buffer size mismatch
Run Code Online (Sandbox Code Playgroud)
也:
print type(self.ui.TextFrom.toPlainText())
# <class 'PyQt4.QtCore.QString'>
Run Code Online (Sandbox Code Playgroud)
您需要QString在传递之前将其转换为Python字符串chardet.改变这个:
chardet.detect(self.ui.TextFrom.toPlainText())
Run Code Online (Sandbox Code Playgroud)
对此:
chardet.detect(str(self.ui.TextFrom.toPlainText()))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1330 次 |
| 最近记录: |