Python 使用QString编码

Python 使用QString编码,python,encoding,Python,Encoding,是否有一个Python库可以检测(或者解码)字符串的编码 我发现了,但它给了我一个错误,使用: 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 mism

是否有一个Python库可以检测(或者解码)字符串的编码

我发现了,但它给了我一个错误,使用:

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
此外:

print type(self.ui.TextFrom.toPlainText())
# <class 'PyQt4.QtCore.QString'>
打印类型(self.ui.TextFrom.toPlainText()) #
我想这是另一种选择

一组帮助函数,用于检测通过HTTP、文件或字符串检索的文本文件(如HTML、XHTML、XML、CSS等)的编码


我想这是另一种选择

一组帮助函数,用于检测通过HTTP、文件或字符串检索的文本文件(如HTML、XHTML、XML、CSS等)的编码


在将
QString
传递给
chardet
之前,需要将其转换为Python字符串。更改此项:

chardet.detect(self.ui.TextFrom.toPlainText())
为此:

chardet.detect(str(self.ui.TextFrom.toPlainText()))

在将
QString
传递给
chardet
之前,需要将其转换为Python字符串。更改此项:

chardet.detect(self.ui.TextFrom.toPlainText())
为此:

chardet.detect(str(self.ui.TextFrom.toPlainText()))

你需要解释为什么chardet不是你想要的-它正是你想要的。对不起,也许它不对,chardet不是我需要的。我在这个库中使用以下文件时出错:chardet.detect(self.ui.TextFrom.toPlainText())get:=chardet.detect(self.ui.TextFrom.toPlainText())文件。。。。u、 提要(aBuf)文件。。。。if self.\u highBitDetector.search(aBuf):类型错误:缓冲区大小不匹配您发布的所有涉及self.ui.TextFrom.toPlainText()的代码中都出现错误-您确定没有提供Unicode字符串吗?或者什么根本不是字符串的东西?打印类型(self.ui.TextFrom.toPlainText())给出了什么?我正在使用Qt和Python(PyQt)。明白了-在将QString传递给chardet之前,需要将其转换为Python字符串。看看我的新答案。你需要解释为什么chardet不是你想要的-它正是你想要的。对不起,也许它不对,chardet不是我需要的。我在这个库中使用以下文件时出错:chardet.detect(self.ui.TextFrom.toPlainText())get:=chardet.detect(self.ui.TextFrom.toPlainText())文件。。。。u、 提要(aBuf)文件。。。。if self.\u highBitDetector.search(aBuf):类型错误:缓冲区大小不匹配您发布的所有涉及self.ui.TextFrom.toPlainText()的代码中都出现错误-您确定没有提供Unicode字符串吗?或者什么根本不是字符串的东西?打印类型(self.ui.TextFrom.toPlainText())给出了什么?我正在使用Qt和Python(PyQt)。明白了-在将QString传递给chardet之前,需要将其转换为Python字符串。查看我的新答案。如何获取字符串的编码信息?encutils.getEncodingInfo(text=self.ui.TextFrom.toPlainText())调用错误:AttributeError:find in _getTextType。如何获取字符串的编码信息?encutils.getEncodingInfo(text=self.ui.TextFrom.toPlainText())调用错误:AttributeError:find in _getTextType。