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


Groups > comp.lang.python > #69999

Re: How to display chinese character in 65001 in pytohn?

Date 2014-04-10 03:27 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: How to display chinese character in 65001 in pytohn?
References <CAOmh4638E4WggAMobFn2qkPbDCgEBkdn5eVub9pjNy2icVuOyA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.9106.1397096867.18130.python-list@python.org> (permalink)

Show all headers | View raw


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())

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


Thread

Re: How to display chinese character in 65001 in pytohn? MRAB <python@mrabarnett.plus.com> - 2014-04-10 03:27 +0100

csiph-web