问题描述
有几个问题我可以在手册中找到答案:
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
推荐答案
s = ...#some ucs-2 string
s.decode(" utf-16")
可能在大多数情况下为您提供正确的结果:
-
此致,
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
这意味着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
不是_from_ ucs2,但是_to_ ucs2,例如:
s = ...#some utf-16 string
d = encode_to_ucs2(s)
可能会为大多数情况提供正确的结果:
-
祝你好运,
Maxim
--
Best regards,
Maxim
这意味着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转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!