[Tutor] Convert Qstring to string in windows
eryksun
eryksun at gmail.com
Sat Oct 18 00:02:36 EDT 2014
On Thu, Oct 16, 2014 at 10:21 AM, C at rlos <cmferras at estudiantes.uci.cu> wrote:
> in linux i do for this way:
> pythonstringtext=qstringtext.text().toUtf8.data()
> and it return a python string correctly.
pythonstringtext is a byte string that has to be decoded as UTF-8.
Here's the 'mojibake' result when it gets decoded as UTF-16LE or
Windows codepages 850 and 1252:
>>> s = u'áéíóú'
>>> b = s.encode('utf-8')
>>> print b.decode('utf-16le')
ꇃ꧃귃돃뫃
>>> print b.decode('850')
├í├®├¡├│├║
>>> print b.decode('1252')
áéÃóú
The native character size in the Windows kernel is 2 bytes, so UTF-16
is the path of least resistance for in-memory strings used with GUI
controls and file/registry paths. UTF-8 is preferred for text data in
files and network communication.
More information about the Python-list
mailing list