2005年02月19日 星期六 17:22
>>> print list(u.encode('utf-16-be'))
[''b', '\x11', 'N', '\xec']
是不是你想要的字符流?
即使这样,接受端一样要使用unicode(received_str, 'utf-16-be')来创建unicode对象,原理和utf-8一样的。
如果你传输的内容全部为中文的话,使用utf-16-be可以比utf-8节省带宽。但如果ASCII字符很多的话,用utf-8就会更省一些。
根据需要选择吧
On Sat, 19 Feb 2005 0:53:44 +0800, cry <zyqmail at 163.net> wrote:
> limodou,您好!
>
> >>> print u
> 我们
> >>> isinstance(u, UnicodeType)
> True
> >>> s_utf8=u.encode("utf-8")
> >>> print list(s_utf8)
> ['\xe6', '\x88', '\x91', '\xe4', '\xbb', '\xac']
> >>> print list(u)
> [u'\u6211', u'\u4eec']
> >>>
>
> 字节的内容都变了。
> 我不能建立一种公共的应用,让所有连接我的服务的程序都进行UTF-8到UNICODE的转换。
>
> 在 2005-02-19 00:41:00 您写道:
> >谁说utf-8把unicode给改了?只是编码不同而已。unicode编码有多种表示,常用
> >的就是utf-8编码。它是一种变长的编码,可以无损地与unicode进行转换。
> >
> >把unicode转换为utf-8就是转换为字符串。而send要的就是字节串呀。你想要什么
> >样的数据队列?最终还是要变成字符串才可以发送。
> >
> >cry wrote:
> >> limodou,您好!
> >>
> >> utf-8已经把UNICODE的编码改变了,好象不太适合我的应用。
> >> 我还是找一找如何把UNICODE字符串变成一个数据队列吧。
> >> 谢谢你的帮助。
> >>
> >
> >
> >--
> >I love python!
> >My Blog: http://www.donews.net/limodou
> >_______________________________________________
> >python-chinese list
> >python-chinese at lists.python.cn
> >http://python.cn/mailman/listinfo/python-chinese
>
> 致
> 礼!
>
> cry
> zyqmail at 163.net
>
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
>
--
Excellent FOSS (Free/Open Source Software):
Get Firefox!
http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
Reclaim Your Inbox!
http://www.spreadfirefox.com/?q=affiliates&id=67907&t=183
Zeuux © 2025
京ICP备05028076号