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

Anthony Liu antonyliu2002 at yahoo.com
Wed Mar 10 04:08:31 CET 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('&#20013;&#21326;&#20154;&#27665;&#20849;&#21644;&#22269;','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.
> 
> ---------------------------------
> 
>
&#25105;&#22312;&#25105;&#30340;Win2K&#19978;&#36816;&#34892;&#22914;&#19979;&#30340;&#20195;&#30721;&#27809;&#26377;&#38382;&#39064;&#12290;
> 
> # -*- coding: cp936 -*-
> import locale
> encoding = locale.getdefaultlocale()[1]
> s1 =
>
unicode('&#20013;&#21326;&#20154;&#27665;&#20849;&#21644;&#22269;',
> encoding)
> s2 =
>
'&#20013;&#21326;&#20154;&#27665;&#20849;&#21644;&#22269;'
> print s1.encode(encoding), s2
> print len(s1), len(s2) # &#36755;&#20986;&#65306;7
14
> 
>
&#20195;&#30721;&#26159;&#20174;&#27004;&#19978;&#26576;&#20301;&#20161;&#20804;&#25552;&#20379;&#30340;&#38142;&#25509;&#19978;&#24471;&#21040;&#30340;&#12290;
> 
>
&#20294;&#26159;&#65292;&#25105;&#22914;&#26524;&#22312;&#23454;&#39564;&#23460;&#30340;Mandrake
>
linux&#19978;&#36816;&#34892;&#36825;&#19968;&#27573;&#31243;&#24207;&#65292;&#23601;&#24471;&#21040;&#22914;&#19979;&#30340;&#38169;&#35823;&#65306;
> 
> SyntaxError: 'unknown encoding: cp936'
> 
>
&#26159;&#19981;&#26159;&#22240;&#20026;&#36825;&#20010;mandrake&#19978;&#27809;&#26377;&#20013;&#25991;&#31995;&#32479;&#65311;
>
&#25105;&#19981;&#26159;&#36229;&#32423;&#31649;&#29702;&#21592;&#65292;&#25105;&#35201;&#35753;&#36229;&#32423;&#29992;&#25143;&#23433;&#35013;&#20160;&#20040;&#19996;&#35199;&#21602;&#65311;
> 
>
Mandrake&#19978;&#30340;locale&#22914;&#19979;&#65306;
> 
> >>> 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