Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79253

Re: [Tutor] Convert Qstring to string in windows

References <1549164247.13980291.1413472329833.JavaMail.zimbra@estudiantes.uci.cu> <969535236.13984943.1413472898089.JavaMail.zimbra@estudiantes.uci.cu>
From eryksun <eryksun@gmail.com>
Date 2014-10-17 23:02 -0500
Subject Re: [Tutor] Convert Qstring to string in windows
Newsgroups comp.lang.python
Message-ID <mailman.14953.1413605000.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Thu, Oct 16, 2014 at 10:21 AM, C@rlos <cmferras@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Tutor] Convert Qstring to string in windows eryksun <eryksun@gmail.com> - 2014-10-17 23:02 -0500

csiph-web