2007年03月01日 星期四 13:02
Hi, All:
Çë½ÌÒ»¸öµÍ¼¶ÎÊÌ⣬ÔÚ´úÂëÖÐÈçºÎ°Ñ¡°Ä㡱ת»»³Éu'\u4f60'£¿
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070301/6d4f5886/attachment.html
2007年03月01日 星期四 13:29
首先你要知道输入是如何编码的,比如假设输入来自windows下的文本文件,一般会是mbcs编码,然后decode之
>>> s='\xc4\xe3'
>>> print '\xc4\xe3'
你
>>> s.decode('mbcs')
u'\u4f60'
>>>
在 07-3-1,Deng Patrick-q19285<kedeng at motorola.com> 写道:
>
>
> Hi, All:
>
>
>
> 请教一个低级问题,在代码中如何把"你"转换成u'\u4f60'?
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
2007年03月01日 星期四 14:12
是这样的,我在Python for Symbian S60上写程序test.py, 目前它的python版本是2.2.2,只支持ISO8859-1编码,因此我需要把“你......”这样的中文在代码test.py中转换成 u'\u4f60...'字符串才好使用。Test.py的代码如下:
# -*- coding: utf8 -*-
s = "你"
print s.encode('utf8')
运行结果如下:
UnicodeEncodeError: 'ascii' codec can't encode character u'\u4f60' in position 0: ordinal
not in range(128)
请问应该如何做才对?
-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of helium
Sent: 2007年3月1日 13:29 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese]在代码中如何把“你”转换成u'\u4f60'?
首先你要知道输入是如何编码的,比如假设输入来自windows下的文本文件,一般会是mbcs编码,然后decode之
>>> s='\xc4\xe3'
>>> print '\xc4\xe3'
你
>>> s.decode('mbcs')
u'\u4f60'
>>>
在 07-3-1,Deng Patrick-q19285<kedeng在motorola.com> 写道:
>
>
> Hi, All:
>
>
>
> 请教一个低级问题,在代码中如何把"你"转换成u'\u4f60'?
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
2007年03月01日 星期四 14:25
这里你得用decode才对。
# -*- coding: utf8 -*-
s = "你"
print s.decode('utf8')
在代码中hard code大约不是个好主意~
On Thu, 01 Mar 2007 14:12:49 +0800, Deng Patrick-q19285
w at public.gmane.org> wrote:
> 是这样的,我在Python for Symbian S60上写程序test.py, 目前它的python版本是
> 2.2.2,只支持ISO8859-1编码,因此我需要把“你......”这样的中文在代码
> test.py中转换成 u'\u4f60...'字符串才好使用。Test.py的代码如下:
>
> # -*- coding: utf8 -*-
> s = "你"
> print s.encode('utf8')
>
> 运行结果如下:
>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u4f60' in
> position 0: ordinal
> not in range(128)
>
> 请问应该如何做才对?
>
>
> -----Original Message-----
> From: python-chinese-bounces at lists.python.cn
> [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of helium
> Sent: 2007年3月1日 13:29 PM
> To: python-chinese at lists.python.cn
> Subject: Re: [python-chinese]在代码中如何把“你”转换成u'\u4f60'?
>
> 首先你要知道输入是如何编码的,比如假设输入来自windows下的文本文件,一般会
> 是mbcs编码,然后decode之
>>>> s='\xc4\xe3'
>>>> print '\xc4\xe3'
> 你
>>>> s.decode('mbcs')
> u'\u4f60'
>>>>
>
> 在 07-3-1,Deng Patrick-q19285<kedeng at motorola.com> 写道:
>>
>>
>> Hi, All:
>>
>>
>>
>> 请教一个低级问题,在代码中如何把"你"转换成u'\u4f60'?
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request at lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
--
Leira Hua
http://my.opera.com/Leira
2007年03月01日 星期四 14:44
谢谢,刚发现写错了应该用decode
这个不用hard code,这样就可以发送中文短信了:
s = "测试中文短信"
logger.info(s.decode('utf8'))
umessaging.sms_send("139xxxxxxxx", s.decode('utf8'))
-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
Sent: 2007年3月1日 14:26 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 在代码中如何把“你”转换成u'\u4f60'?
这里你得用decode才对。
# -*- coding: utf8 -*-
s = "你"
print s.decode('utf8')
在代码中hard code大约不是个好主意~
On Thu, 01 Mar 2007 14:12:49 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> 是这样的,我在Python for Symbian S60上写程序test.py, 目前它的python版本是
> 2.2.2,只支持ISO8859-1编码,因此我需要把“你......”这样的中文在代码
> test.py中转换成 u'\u4f60...'字符串才好使用。Test.py的代码如下:
>
> # -*- coding: utf8 -*-
> s = "你"
> print s.encode('utf8')
>
> 运行结果如下:
>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u4f60' in
> position 0: ordinal not in range(128)
>
> 请问应该如何做才对?
>
>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn
> [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of helium
> Sent: 2007年3月1日 13:29 PM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese]在代码中如何把“你”转换成u'\u4f60'?
>
> 首先你要知道输入是如何编码的,比如假设输入来自windows下的文本文件,一般会
> 是mbcs编码,然后decode之
>>>> s='\xc4\xe3'
>>>> print '\xc4\xe3'
> 你
>>>> s.decode('mbcs')
> u'\u4f60'
>>>>
>
> 在 07-3-1,Deng Patrick-q19285<kedeng在motorola.com> 写道:
>>
>>
>> Hi, All:
>>
>>
>>
>> 请教一个低级问题,在代码中如何把"你"转换成u'\u4f60'?
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to
>> python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to
>> python-chinese-request在lists.python.cn
>> Detail Info:
>> http://python.cn/mailman/listinfo/python-chinese
>>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
--
Leira Hua
http://my.opera.com/Leira
_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Zeuux © 2025
京ICP备05028076号