Reputation: 64366
Is there a Python library which can detect (and perhaps decode) encoding of the string?
I found chardet
but it gives me an error, using:
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
Also:
print type(self.ui.TextFrom.toPlainText())
# <class 'PyQt4.QtCore.QString'>
Upvotes: 1
Views: 1544
Reputation: 281835
You need to convert your QString
to a Python string before passing it to chardet
. Change this:
chardet.detect(self.ui.TextFrom.toPlainText())
to this:
chardet.detect(str(self.ui.TextFrom.toPlainText()))
Upvotes: 7
Reputation: 51
I guess this is another option.
A collection of helper functions to detect encodings of text files (like HTML, XHTML, XML, CSS, etc.) retrieved via HTTP, file or string.
Upvotes: 2