Working with QString Encoding

Is there a Python library that can detect (and possibly decode) the encoding of a 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'>
+1
source share
2 answers

You need to convert QStringto a Python string before passing it to chardet. Change this:

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

:

chardet.detect(str(self.ui.TextFrom.toPlainText()))
+7
source

I think this is another option.

http://cthedot.de/encutils/

A set of helper functions for detecting encodings of text files (such as HTML, XHTML, XML, CSS, etc.) received via HTTP, a file or a string.

+2
source

Source: https://habr.com/ru/post/1749870/


All Articles