[python-chinese] Linux上 # -*- coding: cp936 -*- 出 错

Anthony Liu antonyliu2002 at yahoo.com
Tue Mar 9 22:08:31 EST 2004


Thank you! John.

Yes, gbk encoding works on the Win2K system, just as
cp936 does.

But if I run the same code on the Mandrake, the system
says that gbk is an unknown encoding. The same happens
to cp936.

I did a 'locate cjk' on the Mandrake system and get:

[antony at ocho antony]$ locate cjk
/usr/share/doc/bind-9.2.3/draft/draft-ietf-idn-cjk-01.txt
/usr/share/ghostscript/7.07/examples/cjk
/usr/share/ghostscript/7.07/examples/cjk/all_ac1.ps
/usr/share/ghostscript/7.07/examples/cjk/all_ag1.ps
/usr/share/ghostscript/7.07/examples/cjk/all_aj1.ps
/usr/share/ghostscript/7.07/examples/cjk/all_aj2.ps
/usr/share/ghostscript/7.07/examples/cjk/all_ak1.ps
/usr/share/ghostscript/7.07/examples/cjk/gscjk_ac.ps
/usr/share/ghostscript/7.07/examples/cjk/gscjk_ag.ps
/usr/share/ghostscript/7.07/examples/cjk/gscjk_aj.ps
/usr/share/ghostscript/7.07/examples/cjk/gscjk_ak.ps
/usr/share/ghostscript/7.07/examples/cjk/iso2022.ps
/usr/share/texmf/doc/help/Catalogue/entries/cjk-fonts.html
/usr/share/texmf/doc/help/Catalogue/entries/cjk.html
/usr/share/i18n/locales/translit_cjk_variants
/usr/share/i18n/locales/translit_cjk_compat
/usr/lib/cups/filter/cjktexttops
/usr/X11R6/bin/rxvt.cjk



--- John Li <johnli at ahlt.net> wrote:
> 1) I converted your email--it looks like
> it had an ascii encoding, not a gb encoding.
> 
> 2) On your system, does locale.getdefaultlocale()[1]
> return ISO8859-1 or cp936, after 
> '# -*- coding: cp936 -*-'?
> You can simply use
unicode('中华人民共和国','gbk')
> (cp936 is more of a Microsoft name; 'gbk' is
> more common elsewhere)
> 
> 3) You have to install CJKCodecs from 
> http://cjkpython.i18n.org/ before the unicode()
> and encode() functions work with gbk/cp936.
> 
> ---------------------------------
> 
>
我在我的Win2K上运行如下的代码没有问题。
> 
> # -*- coding: cp936 -*-
> import locale
> encoding = locale.getdefaultlocale()[1]
> s1 =
>
unicode('中华人民共和国',
> encoding)
> s2 =
>
'中华人民共和国'
> print s1.encode(encoding), s2
> print len(s1), len(s2) # 输出:7
14
> 
>
代码是从楼上某位仁兄提供的链接上得到的。
> 
>
但是,我如果在实验室的Mandrake
>
linux上运行这一段程序,就得到如下的错误:
> 
> SyntaxError: 'unknown encoding: cp936'
> 
>
是不是因为这个mandrake上没有中文系统?
>
我不是超级管理员,我要让超级用户安装什么东西呢?
> 
>
Mandrake上的locale如下:
> 
> >>> locale.getdefaultlocale()
> ['en_US', 'ISO8859-1']
> > _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com




More information about the Python-list mailing list