unicode转换 [英] unicode converting
问题描述
有几个问题我可以在手册中找到答案:
1.如何定义哪个是python unicode字符串的内部编码(UTF-8,UTF -16 ...)
2.如何将字符串转换为UCS-2
(freebsd4上的Python 2.2.3)
-
祝你好运,
Maxim
there are a few questions i can find answer in manual:
1. how to define which is internal encoding of python unicode strings (UTF-8, UTF-16 ...)
2. how to convert string to UCS-2
(Python 2.2.3 on freebsd4)
--
Best regards,
Maxim
推荐答案
Maxim Kasimov写道:
Maxim Kasimov wrote:
有几个问题我可以在手册中找到答案:
1.如何定义哪个是python unicode字符串的内部编码
(UTF -8,UTF-16 ......)
这不应该是你关注的问题 - 但是你可以用...来指定它。 ./configure
--enable-unicode = ucs2"或--enable-unicode = ucs4。你不能把它设置为utf-8
或utf-16。
2.如何将字符串转换为UCS-2
there are a few questions i can find answer in manual:
1. how to define which is internal encoding of python unicode strings
(UTF-8, UTF-16 ...)
It shouldn''t be your concern - but you can specify it using " ./configure
--enable-unicode=ucs2" or --enable-unicode=ucs4. You can''t set it to utf-8
or utf-16.
2. how to convert string to UCS-2
s = ...#some ucs-2 string
s.decode(" utf-16")
可能在大多数情况下为您提供正确的结果:
http://mail.python.org/pipermail/pyt...ay/024193.html
-
此致,
Diez B. Roggisch
s = ... # some ucs-2 string
s.decode("utf-16")
might give you the right results for most cases:
http://mail.python.org/pipermail/pyt...ay/024193.html
--
Regards,
Diez B. Roggisch
Diez B. Roggisch写道:
Diez B. Roggisch wrote:
Maxim Kasimov写道:
Maxim Kasimov wrote:
我可以在手册中找到几个问题的答案:
1。如何定义哪个是python unicode字符串的内部编码
(UTF-8,UTF-16 ......)
它不应该是你的顾虑 - 但是你可以用它来指定它" ./configure
--enable-unicode = ucs2"或--enable-unicode = ucs4。你不能把它设置为utf-8
或utf-16。
there are a few questions i can find answer in manual:
1. how to define which is internal encoding of python unicode strings
(UTF-8, UTF-16 ...)
It shouldn''t be your concern - but you can specify it using " ./configure
--enable-unicode=ucs2" or --enable-unicode=ucs4. You can''t set it to utf-8
or utf-16.
这意味着python内部unicode格式是ucs2还是ucs4?
我关心qustion因为我需要用ucs2编码将数据发送到外部
应用程序
is that means that python internal unicode format is ucs2 or ucs4?
i''m concerning with the qustion because i need to send data to external
application in ucs2 encoding
2。如何将字符串转换为UCS-2
s = ...#some ucs-2 string
s.decode(" utf-16")
2. how to convert string to UCS-2
s = ... # some ucs-2 string
s.decode("utf-16")
不是_from_ ucs2,但是_to_ ucs2,例如:
s = ...#some utf-16 string
d = encode_to_ucs2(s)
可能会为大多数情况提供正确的结果:
http://mail.python.org/pipermail/pyt...ay/024193.html
-
祝你好运,
Maxim
--
Best regards,
Maxim
2005年3月15日星期二18:54: 20 + 0200,谣言说Maxim Kasimov
< ka ***** @ i.com.ua>可能写得:
On Tue, 15 Mar 2005 18:54:20 +0200, rumours say that Maxim Kasimov
<ka*****@i.com.ua> might have written:
这不应该是你的顾虑 - 但你可以用"来指定它。 ./configure
--enable-unicode = ucs2"或--enable-unicode = ucs4。你不能把它设置为utf-8
或utf-16。
It shouldn''t be your concern - but you can specify it using " ./configure
--enable-unicode=ucs2" or --enable-unicode=ucs4. You can''t set it to utf-8
or utf-16.
这意味着python内部unicode格式是ucs2还是ucs4?
我很关心使用qustion,因为我需要以ucs2编码将数据发送到外部
应用程序
is that means that python internal unicode format is ucs2 or ucs4?
i''m concerning with the qustion because i need to send data to external
application in ucs2 encoding
如果unicode_data引用您的unicode数据,您只需发送以下内容:
unicode_data.encode(''utf-16'')#可能utf-16be用于网络订单
你不应该关心内部编码unicode对象。
-
TZOTZIOY,我说英格兰最好。
发送和容忍时要严格在接收时。 (来自RFC1958)
我真的应该在与人交谈时牢记这一点,实际上......
If unicode_data references your unicode data, all you have to send is:
unicode_data.encode(''utf-16'') # maybe utf-16be for network order
You should not care about internal encoding of unicode objects.
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
这篇关于unicode转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!