Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70002
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <elearn2014@gmail.com> |
| 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; 'python.': 0.02; 'win32': 0.03; 'broken': 0.04; 'mrab': 0.05; 'output': 0.05; 'binary': 0.07; 'see:': 0.07; 'bytes.': 0.09; 'url:github': 0.09; 'variable,': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'codecs': 0.16; 'skip:< 20': 0.16; 'skip:n 110': 0.16; 'sys.stdout': 0.16; 'url:ch': 0.16; 'win7': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'written': 0.21; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'specify': 0.24; 'tells': 0.24; 'environment': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'post': 0.26; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'skip:p 30': 0.29; 'character': 0.29; 'generally': 0.29; '8bit%:3': 0.30; 'characters': 0.30; 'mode': 0.30; 'skip:& 60': 0.30; 'skip:g 30': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; '8bit%:2': 0.31; 'url:python': 0.33; 'maybe': 0.34; 'display': 0.35; 'but': 0.35; 'received:google.com': 0.35; '8bit%:9': 0.36; 'skip:s 60': 0.36; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'operating': 0.37; 'skip:p 20': 0.39; 'url:mail': 0.40; 'how': 0.40; 'skip:\xc2 10': 0.60; 'tell': 0.60; 'length': 0.61; 'answer.': 0.68; 'chinese': 0.74; 'power': 0.76 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=plqVHVoC9ZERTbJ3EVWI2ByRfICoDKPytc2FJFWVvDU=; b=0eSJUKf22a+tVg95aOTqBFDARfD7qqIYT3u4JB+PVK6ZKYCmcg3wfulutlgzPehC8f fNNMDnBM/BlbAW5u/QoaOfCUtIaGakUmINzkqrxLlzHX+I28A4qbipCOfjskrgKD1jy6 ZBg6SSETbr0SmD0wXdZJunqkdgXsghCoTJOWOprkEgNGzgrmfayYe6hSrqSLWCQqH8IX OTasMTL01ndueLutvR+gZjYT8CJg2k9ufLMSxuMB/eFRKFzY1Od6gtPxrYf78ZzA0HzP sf4m73Qdw5bp7vHhoTyFWLhJ7o5d7fQmYX+lUxqidUJdoao/P/knr7YueS6vzdWnFjb7 mdVw== |
| MIME-Version | 1.0 |
| X-Received | by 10.152.3.72 with SMTP id a8mr10146390laa.33.1397099105609; Wed, 09 Apr 2014 20:05:05 -0700 (PDT) |
| In-Reply-To | <534601A1.5040005@mrabarnett.plus.com> |
| References | <CAOmh4638E4WggAMobFn2qkPbDCgEBkdn5eVub9pjNy2icVuOyA@mail.gmail.com> <534601A1.5040005@mrabarnett.plus.com> |
| Date | Thu, 10 Apr 2014 11:05:05 +0800 |
| Subject | Re: How to display chinese character in 65001 in pytohn? |
| From | length power <elearn2014@gmail.com> |
| To | MRAB <python@mrabarnett.plus.com> |
| Content-Type | multipart/alternative; boundary=089e01419f34e7ec6604f6a77b8f |
| Cc | python-list@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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9107.1397099107.18130.python-list@python.org> (permalink) |
| Lines | 166 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1397099107 news.xs4all.nl 2903 [2001:888:2000:d::a6]:39186 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70002 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
i tried this way ,and post it in stackoverflow,please see:
maybe it is the best answer.
Codepage 65001 is generally broken in binary mode as used by Python 3,
since _write calls Win32 WriteFile, which calls WriteConsoleA, which
returns the number of characters written instead of the number of bytes.
That confuses Python. ANSICON <https://github.com/adoxa/ansicon> can hook
WriteFile to fix this for programs that you specify in an environment
variable, but that won't help with input.
http://stackoverflow.com/questions/22977409/how-to-display-chinese-character-in-65001-in-pytohn?noredirect=1#comment35087732_22977409
2014-04-10 10:27 GMT+08:00 MRAB <python@mrabarnett.plus.com>:
> On 2014-04-10 02:54, length power wrote:
>
>> I am in win7 +python3.3.
>>
>> import os
>> os.system("chcp 936")
>> fh=open("test.ch <http://test.ch>","w",encoding="utf-8")
>>
>> fh.write("你")
>> fh.close()
>> os.system("chcp 65001")
>> fh=open("test.ch <http://test.ch>","r",encoding="utf-8").read()
>>
>> print(fh)
>> Äã
>> >>> print(fh.encode("utf-8"))
>> b'\xe4\xbd\xa0'
>>
>> How can i display the chinese character `你` in 65001?
>>
>> The "chcp 65001" tells the operating system to use UTF-8, but you also
> have to tell Python to output UTF-8. Try this:
>
> from codecs import getwriter
> sys.stdout = getwriter('utf-8')(sys.stdout.detach())
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How to display chinese character in 65001 in pytohn? length power <elearn2014@gmail.com> - 2014-04-10 11:05 +0800
csiph-web