Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'subject:: [': 0.04; 'utf-8': 0.07; 'string': 0.09; 'bytes,': 0.09; 'subject:string': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'gui': 0.12; 'windows': 0.15; 'in-memory': 0.16; 'paths.': 0.16; 'subject:Convert': 0.16; 'subject:Tutor': 0.16; 'subject:windows': 0.16; 'wrote:': 0.18; 'skip:p 40': 0.19; 'thu,': 0.19; 'subject:] ': 0.20; '>>>': 0.22; 'preferred': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**1': 0.23; 'byte': 0.24; 'least': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'message- id:@mail.gmail.com': 0.30; 'correctly.': 0.31; 'text': 0.33; 'linux': 0.33; 'cc:no real name:2**1': 0.33; 'received:google.com': 0.35; 'controls': 0.36; 'files': 0.38; 'skip:u 10': 0.60; '8bit%:100': 0.72; '8bit%:77': 0.84; 'resistance': 0.84; '850': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=J5rUeUrRDCWqpiFOsirgCcYEjHPzoBJ0t/HP6/X7nYA=; b=lBA+wc2MxPJ73ZRUR9uImfjlSMxcY7mBkJDdN3RsMk5HGoT9R+CIHePkG1xQkQWQPP K0xOP2F16Cl0KfJJGimp7NhBRZE8kiGFXqCBRRnDWKT2LTJczEKTZbFMvAuqfEjcoT+K 61dF1SPKqC41T7jlDTVKZu2UJdyuRqY3XNZCh1APyaPRG5UEGwuQV/3WygPg9MGTy1il z90MNcmnu+UAcbEC9nDxVgGyZ3Kh+mH6zIp41M7+Ag7KSPChgU4xvE0DGqw0Ej1MNGuu JXohJcINXTBS8BhS18Q/Lv9wTV6QLNI8kiJPuXgehM8PN7kfvv8dS4HVpEoCOYvFjZX7 XKXQ== X-Received: by 10.140.39.134 with SMTP id v6mr5905107qgv.19.1413604996915; Fri, 17 Oct 2014 21:03:16 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <969535236.13984943.1413472898089.JavaMail.zimbra@estudiantes.uci.cu> References: <1549164247.13980291.1413472329833.JavaMail.zimbra@estudiantes.uci.cu> <969535236.13984943.1413472898089.JavaMail.zimbra@estudiantes.uci.cu> From: eryksun Date: Fri, 17 Oct 2014 23:02:36 -0500 Subject: Re: [Tutor] Convert Qstring to string in windows To: "C@rlos" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, tutor@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413605000 news.xs4all.nl 2877 [2001:888:2000:d::a6]:54373 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79253 On Thu, Oct 16, 2014 at 10:21 AM, C@rlos wrot= e: > in linux i do for this way: > pythonstringtext=3Dqstringtext.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 =3D u'=C3=A1=C3=A9=C3=AD=C3=B3=C3=BA' >>> b =3D s.encode('utf-8') >>> print b.decode('utf-16le') =EA=87=83=EA=A7=83=EA=B7=83=EB=8F=83=EB=AB=83 >>> print b.decode('850') =E2=94=9C=C3=AD=E2=94=9C=C2=AE=E2=94=9C=C2=A1=E2=94=9C=E2=94=82=E2=94= =9C=E2=95=91 >>> print b.decode('1252') =C3=83=C2=A1=C3=83=C2=A9=C3=83=C2=AD=C3=83=C2=B3=C3=83=C2=BA 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.