Chinese language support of Python?

Martin v. Loewis martin at v.loewis.de
Sun Jul 7 04:01:05 EDT 2002


guidance_shanghai at yahoo.com.cn (Leon Wang) writes:

> But still can not put Chinese directly as string in source, I can not
> live with so much \u... for a whole Chinese sensence/paragraph, it's
> impossible to read and edit them :(

This is a known problem, and it will be addressed with PEP 263
(http://www.python.org/peps/pep-0263.html).

Meanwhile, you have the following options:

- Don't use IDLE to edit Python source code (but, say, notepad), and
  only put Chinese text into string literals.
- Set the default encoding in site.py to the encoding you want to use.
- Apply patch 
  http://sourceforge.net/tracker/index.php?func=detail&aid=508973&group_id=9579&atid=309579

  which allows you to declare the source encoding for IDLE.

In either case, you cannot use Chinese in Unicode literals. Instead,
you should always use 

   unicode("chinese string", "chinese encoding")

For portability, and if your editors support it, I recommend to use
UTF-8 as the "chinese encoding".

Regards,
Martin



More information about the Python-list mailing list