Python论坛  - 讨论区

标题:[python-chinese] 还是两个编码问题

2007年03月05日 星期一 10:39

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 10:39:36 HKT 2007

问题1:
 
我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
>>> # -*- coding: utf8 -*-
>>> s = "中国"
>>> s
'\xd6\xd0\xb9\xfa'
>>> isinstance(s, str)
True
>>> unicode(s, "gb2312")
u'\u4e2d\u56fd'
>>> s.decode("gb2312")
u'\u4e2d\u56fd'
 
但我在test.py中完全一样这么写,却报错:
# -*- coding: utf8 -*-
s = "中国"
print s
print isinstance(s, str)
print unicode(s, "gb2312")
print s.decode(s, "gb2312")
运行结果:
涓浗
True
Traceback (most recent call last):
  File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
    print unicode(s, "gb2312")
UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3: illegal multibyte s
equence

请问这是为何?
 
 
问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是"utf8",两者有不同么?我之前好像记得"utf-8"在什么情况下会有问题的,但现在一下子想不起来了。
http://www.motorola.com.cn>  
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070305/0502f46e/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:07

Zoom.Quiet zoom.quiet在gmail.com
星期一 三月 5 11:07:41 HKT 2007

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
>
> 问题1:
>
> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
IDLE 中的所有都是 unicode 处理的
> >>> # -*- coding: utf8 -*-
> >>> s = "中国"
> >>> s
> '\xd6\xd0\xb9\xfa'
> >>> isinstance(s, str)
> True
> >>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
> >>> s.decode("gb2312")
> u'\u4e2d\u56fd'
>
> 但我在test.py中完全一样这么写,却报错:
你的 test.py 本身的编码是否 utf-8 ?
> # -*- coding: utf8 -*-
> s = "中国"
> print s
> print isinstance(s, str)
> print unicode(s, "gb2312")
> print s.decode(s, "gb2312")
> 运行结果:
> 涓浗
> True
> Traceback (most recent call last):
>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in
> 
>     print unicode(s, "gb2312")
> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> illegal multibyte s
> equence
>
> 请问这是为何?
>
>
> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是"utf8",两者有不同么?我之前好像记得"utf-8"在什么情况下会有问题的,但现在一下子想不起来了。
>
> _______________________________________________
> 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
>


-- 
'''Time is unimportant, only life important!
http://zoomquiet.org
blog在http://blog.zoomquiet.org/pyblosxom/
wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
scrap在http://floss.zoomquiet.org
douban在http://www.douban.com/people/zoomq/
____________________________________
Pls. use OpenOffice.org to replace M$ Office.
     http://zh.openoffice.org
Pls. use 7-zip to replace WinRAR/WinZip.
     http://7-zip.org/zh-cn/
You can get the truely Freedom 4 software.
'''

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:10

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 11:10:24 HKT 2007

除了引用无其它内容,Zoom.quiet你想说什么? 

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Zoom.Quiet
Sent: 2007年3月5日 11:08 AM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 还是两个编码问题

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
>
> 问题1:
>
> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
IDLE 中的所有都是 unicode 处理的
> >>> # -*- coding: utf8 -*-
> >>> s = "中国"
> >>> s
> '\xd6\xd0\xb9\xfa'
> >>> isinstance(s, str)
> True
> >>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
> >>> s.decode("gb2312")
> u'\u4e2d\u56fd'
>
> 但我在test.py中完全一样这么写,却报错:
你的 test.py 本身的编码是否 utf-8 ?
> # -*- coding: utf8 -*-
> s = "中国"
> print s
> print isinstance(s, str)
> print unicode(s, "gb2312")
> print s.decode(s, "gb2312")
> 运行结果:
> 涓浗
> True
> Traceback (most recent call last):
>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>     print unicode(s, "gb2312")
> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> illegal multibyte s
> equence
>
> 请问这是为何?
>
>
> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是"utf8",两者有不同么?我之前好像记得"utf-8"在
> 什么情况下会有问题的,但现在一下子想不起来了。
>
> _______________________________________________
> 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
>


--
'''Time is unimportant, only life important!
http://zoomquiet.org
blog在http://blog.zoomquiet.org/pyblosxom/
wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
scrap在http://floss.zoomquiet.org
douban在http://www.douban.com/people/zoomq/
____________________________________
Pls. use OpenOffice.org to replace M$ Office.
     http://zh.openoffice.org
Pls. use 7-zip to replace WinRAR/WinZip.
     http://7-zip.org/zh-cn/
You can get the truely Freedom 4 software.
'''
_______________________________________________
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:20

lubiao lubiao.py在gmail.com
星期一 三月 5 11:20:49 HKT 2007

> 除了引用无其它内容,Zoom.quiet你想说什么?

你的 test.py 本身的编码是否 utf-8 ?

请确认 你用你的 文本编辑器 编辑 test.py 后, 是按 utf8 保存的,

不知你是否认为 你写了 "# -*- coding: utf8 -*-"   test.py  就是 utf8 编码

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:21

Leira Hua lhua在altigen.com.cn
星期一 三月 5 11:21:23 HKT 2007


你的脚本文件中指明使用utf-8编码,但却试图使用GB2312去解码其中的utf-8  
string literal,自然会出错

> # -*- coding: utf8 -*-
# 这行说明这个脚本为utf-8编码
> s = "中国"
# 所以这是一个utf-8编码的字符串
> print s
# 将一个utf-8编码的字符串在默认GBK的windows命令行窗口中打印,自然会使乱码
> print isinstance(s, str)
> print unicode(s, "gb2312")
# 试图将utf-8的字符串以GB2312编码,出错
> print s.decode(s, "gb2312")

GB2312以及GBK/GB18030等编码标准都已经过时了,为什么不都用UTF-8呢?

另外,UTF-8是标准说法吧?不过一般情况下,UTF8/UTF-8可以混用。
参见 http://www.cl.cam.ac.uk/~mgk25/unicode.html


On Mon, 05 Mar 2007 10:39:36 +0800, Deng Patrick-q19285  
w at public.gmane.org> wrote:

> 问题1:
> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
>>>> # -*- coding: utf8 -*-
>>>> s = "中国"
>>>> s
> '\xd6\xd0\xb9\xfa'
>>>> isinstance(s, str)
> True
>>>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
>>>> s.decode("gb2312")
> u'\u4e2d\u56fd'
> 但我在test.py中完全一样这么写,却报错:
> # -*- coding: utf8 -*-
> s = "中国"
> print s
> print isinstance(s, str)
> print unicode(s, "gb2312")
> print s.decode(s, "gb2312")
> 运行结果:
> 涓浗
> True
> Traceback (most recent call last):
>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>     print unicode(s, "gb2312")
> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:  
> illegal multibyte s
> equence
>
> 请问这是为何?
> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是 
> "utf8",两者有不同么?我之前好像记得"utf-8"在什么情况下会有问题的,但现在 
> 一下子想不起来了。
> http://www.motorola.com.cn>



-- 
Leira Hua
http://my.opera.com/Leira


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:25

Leira Hua lhua在altigen.com.cn
星期一 三月 5 11:25:39 HKT 2007


别人回复你的问题是出于好意,仔细阅读别人的解答是一种礼貌. Zoom.quiet是这儿的 
前辈,而且他的解答切中要害,你应该仔细看看,并注意基本的礼貌。这儿没有任何 
人有义务回答你的任何问题。

On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285  
w at public.gmane.org> wrote:

> 除了引用无其它内容,Zoom.quiet你想说什么?
>
> -----Original Message-----
> From: python-chinese-bounces at lists.python.cn  
> [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Zoom.Quiet
> Sent: 2007年3月5日 11:08 AM
> To: python-chinese at lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> On 3/5/07, Deng Patrick-q19285 <kedeng at motorola.com> wrote:
>>
>>
>> 问题1:
>>
>> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
> IDLE 中的所有都是 unicode 处理的
>> >>> # -*- coding: utf8 -*-
>> >>> s = "中国"
>> >>> s
>> '\xd6\xd0\xb9\xfa'
>> >>> isinstance(s, str)
>> True
>> >>> unicode(s, "gb2312")
>> u'\u4e2d\u56fd'
>> >>> s.decode("gb2312")
>> u'\u4e2d\u56fd'
>>
>> 但我在test.py中完全一样这么写,却报错:
> 你的 test.py 本身的编码是否 utf-8 ?
>> # -*- coding: utf8 -*-
>> s = "中国"
>> print s
>> print isinstance(s, str)
>> print unicode(s, "gb2312")
>> print s.decode(s, "gb2312")
>> 运行结果:
>> 涓浗
>> True
>> Traceback (most recent call last):
>>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>>     print unicode(s, "gb2312")
>> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
>> illegal multibyte s
>> equence
>>
>> 请问这是为何?
>>
>>
>> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是 
>> "utf8",两者有不同么?我之前好像记得"utf-8"在
>> 什么情况下会有问题的,但现在一下子想不起来了。
>>
>> _______________________________________________
>> 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
>>
>
>
> --
> '''Time is unimportant, only life important!
> http://zoomquiet.org
> blog at http://blog.zoomquiet.org/pyblosxom/
> wiki at http://wiki.woodpecker.org.cn/moin/ZoomQuiet
> scrap at http://floss.zoomquiet.org
> douban at http://www.douban.com/people/zoomq/
> ____________________________________
> Pls. use OpenOffice.org to replace M$ Office.
>      http://zh.openoffice.org
> Pls. use 7-zip to replace WinRAR/WinZip.
>      http://7-zip.org/zh-cn/
> You can get the truely Freedom 4 software.
> '''
> _______________________________________________
> 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


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:28

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 11:28:36 HKT 2007

那为何同样的代码在IDLE中正常? 
>>>> # -*- coding: utf8 -*-
>>>> s = "中国"
>>>> s
> '\xd6\xd0\xb9\xfa'
>>>> isinstance(s, str)
> True
>>>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
>>>> s.decode("gb2312")
> u'\u4e2d\u56fd'

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
Sent: 2007年3月5日 11:21 AM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 还是两个编码问题

你的脚本文件中指明使用utf-8编码,但却试图使用GB2312去解码其中的utf-8
string literal,自然会出错

> # -*- coding: utf8 -*-
# 这行说明这个脚本为utf-8编码
> s = "中国"
# 所以这是一个utf-8编码的字符串
> print s
# 将一个utf-8编码的字符串在默认GBK的windows命令行窗口中打印,自然会使乱码
> print isinstance(s, str)
> print unicode(s, "gb2312")
# 试图将utf-8的字符串以GB2312编码,出错
> print s.decode(s, "gb2312")

GB2312以及GBK/GB18030等编码标准都已经过时了,为什么不都用UTF-8呢?

另外,UTF-8是标准说法吧?不过一般情况下,UTF8/UTF-8可以混用。
参见 http://www.cl.cam.ac.uk/~mgk25/unicode.html


On Mon, 05 Mar 2007 10:39:36 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:

> 问题1:
> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
>>>> # -*- coding: utf8 -*-
>>>> s = "中国"
>>>> s
> '\xd6\xd0\xb9\xfa'
>>>> isinstance(s, str)
> True
>>>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
>>>> s.decode("gb2312")
> u'\u4e2d\u56fd'
> 但我在test.py中完全一样这么写,却报错:
> # -*- coding: utf8 -*-
> s = "中国"
> print s
> print isinstance(s, str)
> print unicode(s, "gb2312")
> print s.decode(s, "gb2312")
> 运行结果:
> 涓浗
> True
> Traceback (most recent call last):
>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>     print unicode(s, "gb2312")
> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:  
> illegal multibyte s
> equence
>
> 请问这是为何?
> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是
> "utf8",两者有不同么?我之前好像记得"utf-8"在什么情况下会有问题的,但现在
> 一下子想不起来了。
> http://www.motorola.com.cn>



--
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:32

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 11:32:15 HKT 2007

Hi, Lubiao:
    我还真是认为"# -*- coding: utf8 -*-"标上了test.py里的字符串就应该全是utf8编码的了。 

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of lubiao
Sent: 2007年3月5日 11:21 AM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 还是两个编码问题

> 除了引用无其它内容,Zoom.quiet你想说什么?

你的 test.py 本身的编码是否 utf-8 ?

请确认 你用你的 文本编辑器 编辑 test.py 后, 是按 utf8 保存的,

不知你是否认为 你写了 "# -*- coding: utf8 -*-"   test.py  就是 utf8 编码
_______________________________________________
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:34

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 11:34:13 HKT 2007

不是吧,我说错什么了?哪里不礼貌了?真是晕了。
下面的邮件除了引用无其它回复,我以为Quiet大虾是不是回复邮件的时候弄错了呢,所以才问问他想说什么。
哥们你火气好大啊。

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
Sent: 2007年3月5日 11:26 AM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 还是两个编码问题

别人回复你的问题是出于好意,仔细阅读别人的解答是一种礼貌. Zoom.quiet是这儿的
前辈,而且他的解答切中要害,你应该仔细看看,并注意基本的礼貌。这儿没有任何
人有义务回答你的任何问题。

On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:

> 除了引用无其它内容,Zoom.quiet你想说什么?
>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn
> [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of 
> Zoom.Quiet
> Sent: 2007年3月5日 11:08 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>>
>>
>> 问题1:
>>
>> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
> IDLE 中的所有都是 unicode 处理的
>> >>> # -*- coding: utf8 -*-
>> >>> s = "中国"
>> >>> s
>> '\xd6\xd0\xb9\xfa'
>> >>> isinstance(s, str)
>> True
>> >>> unicode(s, "gb2312")
>> u'\u4e2d\u56fd'
>> >>> s.decode("gb2312")
>> u'\u4e2d\u56fd'
>>
>> 但我在test.py中完全一样这么写,却报错:
> 你的 test.py 本身的编码是否 utf-8 ?
>> # -*- coding: utf8 -*-
>> s = "中国"
>> print s
>> print isinstance(s, str)
>> print unicode(s, "gb2312")
>> print s.decode(s, "gb2312")
>> 运行结果:
>> 涓浗
>> True
>> Traceback (most recent call last):
>>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>>     print unicode(s, "gb2312")
>> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
>> illegal multibyte s
>> equence
>>
>> 请问这是为何?
>>
>>
>> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是
>> "utf8",两者有不同么?我之前好像记得"utf-8"在
>> 什么情况下会有问题的,但现在一下子想不起来了。
>>
>> _______________________________________________
>> 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
>>
>
>
> --
> '''Time is unimportant, only life important!
> http://zoomquiet.org
> blog在http://blog.zoomquiet.org/pyblosxom/
> wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
> scrap在http://floss.zoomquiet.org
> douban在http://www.douban.com/people/zoomq/
> ____________________________________
> Pls. use OpenOffice.org to replace M$ Office.
>      http://zh.openoffice.org
> Pls. use 7-zip to replace WinRAR/WinZip.
>      http://7-zip.org/zh-cn/
> You can get the truely Freedom 4 software.
> '''
> _______________________________________________
> 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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:37

lubiao lubiao.py在gmail.com
星期一 三月 5 11:37:05 HKT 2007

# -*- coding: utf8 -*-
´Ë¾ä  ÔÚ IDLEÖÐ ²»Æð×÷ÓÃ

ÔÚ IDLE Öл¹ÊÇ gb2312


On 3/5/07, Deng Patrick-q19285 <kedeng at motorola.com> wrote:
> ÄÇΪºÎͬÑùµÄ´úÂëÔÚIDLEÖÐÕý³££¿
> >>>> # -*- coding: utf8 -*-
> >>>> s = "Öйú"
> >>>> s
> > '\xd6\xd0\xb9\xfa'
> >>>> isinstance(s, str)
> > True
> >>>> unicode(s, "gb2312")
> > u'\u4e2d\u56fd'
> >>>> s.decode("gb2312")
> > u'\u4e2d\u56fd'
>
> -----Original Message-----
> From: python-chinese-bounces at lists.python.cn [mailto:python-chinese-bounces at lists.python.cn] On Behalf Of Leira Hua
> Sent: 2007Äê3ÔÂ5ÈÕ 11:21 AM
> To: python-chinese at lists.python.cn
> Subject: Re: [python-chinese] »¹ÊÇÁ½¸ö±àÂëÎÊÌâ
>
> ÄãµÄ½Å±¾ÎļþÖÐÖ¸Ã÷ʹÓÃutf-8±àÂ룬µ«È´ÊÔͼʹÓÃGB2312È¥½âÂëÆäÖеÄutf-8
> string literal,×ÔÈ»»á³ö´í
>
> > # -*- coding: utf8 -*-
> # ÕâÐÐ˵Ã÷Õâ¸ö½Å±¾Îªutf-8±àÂë
> > s = "Öйú"
> # ËùÒÔÕâÊÇÒ»¸öutf-8±àÂëµÄ×Ö·û´®
> > print s
> # ½«Ò»¸öutf-8±àÂëµÄ×Ö·û´®ÔÚĬÈÏGBKµÄwindowsÃüÁîÐд°¿ÚÖдòÓ¡£¬×ÔÈ»»áʹÂÒÂë
> > print isinstance(s, str)
> > print unicode(s, "gb2312")
> # ÊÔͼ½«utf-8µÄ×Ö·û´®ÒÔGB2312±àÂ룬³ö´í
> > print s.decode(s, "gb2312")
>
> GB2312ÒÔ¼°GBK/GB18030µÈ±àÂë±ê×¼¶¼ÒѾ­¹ýʱÁË£¬ÎªÊ²Ã´²»¶¼ÓÃUTF-8ÄØ£¿
>
> ÁíÍ⣬UTF-8ÊDZê׼˵·¨°É£¿²»¹ýÒ»°ãÇé¿öÏ£¬UTF8/UTF-8¿ÉÒÔ»ìÓá£
> ²Î¼û http://www.cl.cam.ac.uk/~mgk25/unicode.html
>
>
> On Mon, 05 Mar 2007 10:39:36 +0800, Deng Patrick-q19285 <kedeng at motorola.com> wrote:
>
> > ÎÊÌâ1£º
> > ÎÒÔÚPython 2.5µÄIDLE 1.2ÖÐÊäÈëÈçÏÂÓï¾äµÃµ½Õý³£½á¹û£º
> >>>> # -*- coding: utf8 -*-
> >>>> s = "Öйú"
> >>>> s
> > '\xd6\xd0\xb9\xfa'
> >>>> isinstance(s, str)
> > True
> >>>> unicode(s, "gb2312")
> > u'\u4e2d\u56fd'
> >>>> s.decode("gb2312")
> > u'\u4e2d\u56fd'
> > µ«ÎÒÔÚtest.pyÖÐÍêÈ«Ò»ÑùÕâôд£¬È´±¨´í£º
> > # -*- coding: utf8 -*-
> > s = "Öйú"
> > print s
> > print isinstance(s, str)
> > print unicode(s, "gb2312")
> > print s.decode(s, "gb2312")
> > ÔËÐнá¹û£º
> > 中国
> > True
> > Traceback (most recent call last):
> >   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
> >     print unicode(s, "gb2312")
> > UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> > illegal multibyte s
> > equence
> >
> > ÇëÎÊÕâÊÇΪºÎ£¿
> > ÎÊÌâ2:¹ØÓÚUTF8±àÂ룬ÎÒÔںܶàµØ·½¿´µ½ÊÇÓÃ×Ö·û´®"utf-8"£¬Ò²Óв»Éٵط½ÊÇ
> > "utf8"£¬Á½ÕßÓв»Í¬Ã´£¿ÎÒ֮ǰºÃÏñ¼ÇµÃ"utf-8"ÔÚʲôÇé¿öÏ»áÓÐÎÊÌâµÄ£¬µ«ÏÖÔÚ
> > Ò»ÏÂ×ÓÏë²»ÆðÀ´ÁË¡£
> > http://www.motorola.com.cn>
>
>
>
> --
> Leira Hua
> http://my.opera.com/Leira
>
> _______________________________________________
> 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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:37

Zoom.Quiet zoom.quiet在gmail.com
星期一 三月 5 11:37:52 HKT 2007

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> Hi, Lubiao:
>     我还真是认为"# -*- coding: utf8 -*-"标上了test.py里的字符串就应该全是utf8编码的了。
这是谣传....
嗬嗬嗬,文本文件本身的编码和文档中的声明,没有关系的,
因为 "# coding = utf8" 是给 Python 解析器看的,
而文件本身是操作系统处理的,
Python 作为高级应用平台,无权擅自处理文件本身的

此为,逻辑问题,不是技术问题...

>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of lubiao
> Sent: 2007年3月5日 11:21 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> > 除了引用无其它内容,Zoom.quiet你想说什么?
>
> 你的 test.py 本身的编码是否 utf-8 ?
>
> 请确认 你用你的 文本编辑器 编辑 test.py 后, 是按 utf8 保存的,
>
> 不知你是否认为 你写了 "# -*- coding: utf8 -*-"   test.py  就是 utf8 编码
> _______________________________________________
> 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


-- 
'''Time is unimportant, only life important!
http://zoomquiet.org
blog在http://blog.zoomquiet.org/pyblosxom/
wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
scrap在http://floss.zoomquiet.org
douban在http://www.douban.com/people/zoomq/
____________________________________
Pls. use OpenOffice.org to replace M$ Office.
     http://zh.openoffice.org
Pls. use 7-zip to replace WinRAR/WinZip.
     http://7-zip.org/zh-cn/
You can get the truely Freedom 4 software.
'''

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:39

Zoom.Quiet zoom.quiet在gmail.com
星期一 三月 5 11:39:49 HKT 2007

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> 不是吧,我说错什么了?哪里不礼貌了?真是晕了。
> 下面的邮件除了引用无其它回复,我以为Quiet大虾是不是回复邮件的时候弄错了呢,所以才问问他想说什么。
> 哥们你火气好大啊。
是也乎,没有关系,只是表述没有到位,
俺没有在意,就此打住吧;
刚好 http://wiki.woodpecker.org.cn/moin/BPUG/2007-03-03
Alex 有关编码的真空体验可以给些提示,
建议阅读他的Blog 文章,或是录音

>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
> Sent: 2007年3月5日 11:26 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> 别人回复你的问题是出于好意,仔细阅读别人的解答是一种礼貌. Zoom.quiet是这儿的
> 前辈,而且他的解答切中要害,你应该仔细看看,并注意基本的礼貌。这儿没有任何
> 人有义务回答你的任何问题。
>
> On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
> > 除了引用无其它内容,Zoom.quiet你想说什么?
> >
> > -----Original Message-----
> > From: python-chinese-bounces在lists.python.cn
> > [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of
> > Zoom.Quiet
> > Sent: 2007年3月5日 11:08 AM
> > To: python-chinese在lists.python.cn
> > Subject: Re: [python-chinese] 还是两个编码问题
> >
> > On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> >>
> >>
> >> 问题1:
> >>
> >> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
> > IDLE 中的所有都是 unicode 处理的
> >> >>> # -*- coding: utf8 -*-
> >> >>> s = "中国"
> >> >>> s
> >> '\xd6\xd0\xb9\xfa'
> >> >>> isinstance(s, str)
> >> True
> >> >>> unicode(s, "gb2312")
> >> u'\u4e2d\u56fd'
> >> >>> s.decode("gb2312")
> >> u'\u4e2d\u56fd'
> >>
> >> 但我在test.py中完全一样这么写,却报错:
> > 你的 test.py 本身的编码是否 utf-8 ?
> >> # -*- coding: utf8 -*-
> >> s = "中国"
> >> print s
> >> print isinstance(s, str)
> >> print unicode(s, "gb2312")
> >> print s.decode(s, "gb2312")
> >> 运行结果:
> >> 涓浗
> >> True
> >> Traceback (most recent call last):
> >>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
> >>     print unicode(s, "gb2312")
> >> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> >> illegal multibyte s
> >> equence
> >>
> >> 请问这是为何?
> >>
> >>
> >> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是
> >> "utf8",两者有不同么?我之前好像记得"utf-8"在
> >> 什么情况下会有问题的,但现在一下子想不起来了。
> >>
> >> _______________________________________________
> >> 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
> >>
> >
> >
> > --
> > '''Time is unimportant, only life important!
> > http://zoomquiet.org
> > blog在http://blog.zoomquiet.org/pyblosxom/
> > wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
> > scrap在http://floss.zoomquiet.org
> > douban在http://www.douban.com/people/zoomq/
> > ____________________________________
> > Pls. use OpenOffice.org to replace M$ Office.
> >      http://zh.openoffice.org
> > Pls. use 7-zip to replace WinRAR/WinZip.
> >      http://7-zip.org/zh-cn/
> > You can get the truely Freedom 4 software.
> > '''
> > _______________________________________________
> > 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
> _______________________________________________
> 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


-- 
'''Time is unimportant, only life important!
http://zoomquiet.org
blog在http://blog.zoomquiet.org/pyblosxom/
wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
scrap在http://floss.zoomquiet.org
douban在http://www.douban.com/people/zoomq/
____________________________________
Pls. use OpenOffice.org to replace M$ Office.
     http://zh.openoffice.org
Pls. use 7-zip to replace WinRAR/WinZip.
     http://7-zip.org/zh-cn/
You can get the truely Freedom 4 software.
'''

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:41

头太晕 torrycn在gmail.com
星期一 三月 5 11:41:41 HKT 2007

ÔÚ07-3-5£¬Deng Patrick-q19285 <kedeng在motorola.com> дµÀ£º
>
>  ÎÊÌâ1£º
>
> ÎÒÔÚPython 2.5µÄIDLE 1.2ÖÐÊäÈëÈçÏÂÓï¾äµÃµ½Õý³£½á¹û£º
> >>> # -*- coding: utf8 -*-
> >>> s = "Öйú"
> >>> s
> '\xd6\xd0\xb9\xfa'
>

´ÓÕâÀï¿ÉÒÔ¿´³ö,"Öйú"ÕâÁ½¸ö×ÖÆäʵÊÇÓÃϵͳĬÈϵÄgb2312±àÂëµÄ.¹À¼ÆÊÇ#-*- coding: utf-8 -*-ÔÚ½»»¥»·¾³Öв¢Ã»ÓÐÆð×÷ÓÃ.ËùÒÔ
,ÄãÔÚÏÂÃæÓÃunicode(s,"gb2312")ÊÇÕý³£µÄ.

>>> isinstance(s, str)
> True
> >>> unicode(s, "gb2312")
> u'\u4e2d\u56fd'
> >>> s.decode("gb2312")
> u'\u4e2d\u56fd'
>
> µ«ÎÒÔÚtest.pyÖÐÍêÈ«Ò»ÑùÕâôд£¬È´±¨´í£º
> # -*- coding: utf8 -*-
> s = "Öйú"
> print s
> print isinstance(s, str)
> print unicode(s, "gb2312")
> print s.decode(s, "gb2312")
> ÔËÐнá¹û£º
> 中国
> True
> Traceback (most recent call last):
>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
>     print unicode(s, "gb2312")
> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> illegal multibyte s
> equence
> ÇëÎÊÕâÊÇΪºÎ£¿
>

ÕâÀïÓÉÓÚÄãʹÓÃÁË# -*- coding: utf8 -*-,ËùÄãËùʹÓõÄIDEÒ²Ðí¾Í°²utf-8±£´æÁËÄãµÄÎļþ,ͬʱÕâ¾ä# -*- coding:
utf8
-*-ÔÚ½âÊÍÖ´ÐÐʱÆðÁË×÷ÓÃ,ËùÒÔÄãÕâÀïµÄ"Öйú"Ó¦¸ÃÊÇutf-8µÄ,ËùÒÔ,ÄãÒÔÏÂÃæµÄ´úÂëÖÐ,Ó¦¸ÃʹÓÃ"utf-8",µ«ÊÇÄãʹÓÃÁËunicode(s,'gb2312'),ËùÒԾͱ¨´íÁË.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070305/60066b44/attachment-0001.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 11:48

limodou limodou在gmail.com
星期一 三月 5 11:48:03 HKT 2007

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> ²»ÊÇ°É£¬ÎÒ˵´íʲôÁË£¿ÄÄÀï²»ÀñòÁË£¿ÕæÊÇÔÎÁË¡£
> ÏÂÃæµÄÓʼþ³ýÁËÒýÓÃÎÞÆäËü»Ø¸´£¬ÎÒÒÔΪQuiet´óϺÊDz»Êǻظ´ÓʼþµÄʱºòŪ´íÁËÄØ£¬ËùÒÔ²ÅÎÊÎÊËûÏë˵ʲô¡£
> ¸çÃÇÄã»ðÆøºÃ´ó°¡¡£
>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
> Sent: 2007Äê3ÔÂ5ÈÕ 11:26 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] »¹ÊÇÁ½¸ö±àÂëÎÊÌâ
>
> ±ðÈ˻ظ´ÄãµÄÎÊÌâÊdzöÓÚºÃÒâ,×ÐϸÔĶÁ±ðÈ˵Ľâ´ðÊÇÒ»ÖÖÀñò. Zoom.quietÊÇÕâ¶ùµÄ
> Ç°±²£¬¶øÇÒËûµÄ½â´ðÇÐÖÐÒªº¦£¬ÄãÓ¦¸Ã×Ðϸ¿´¿´£¬²¢×¢Òâ»ù±¾µÄÀñò¡£Õâ¶ùûÓÐÈκÎ
> ÈËÓÐÒåÎñ»Ø´ðÄãµÄÈκÎÎÊÌâ¡£
>
> On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
> > ³ýÁËÒýÓÃÎÞÆäËüÄÚÈÝ£¬Zoom.quietÄãÏë˵ʲô?
> >
> > -----Original Message-----
> > From: python-chinese-bounces在lists.python.cn
> > [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of
> > Zoom.Quiet
> > Sent: 2007Äê3ÔÂ5ÈÕ 11:08 AM
> > To: python-chinese在lists.python.cn
> > Subject: Re: [python-chinese] »¹ÊÇÁ½¸ö±àÂëÎÊÌâ
> >
> > On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> >>
> >>
> >> ÎÊÌâ1£º
> >>
> >> ÎÒÔÚPython 2.5µÄIDLE 1.2ÖÐÊäÈëÈçÏÂÓï¾äµÃµ½Õý³£½á¹û£º
> > IDLE ÖеÄËùÓж¼ÊÇ unicode ´¦ÀíµÄ
> >> >>> # -*- coding: utf8 -*-
> >> >>> s = "Öйú"
> >> >>> s
> >> '\xd6\xd0\xb9\xfa'
> >> >>> isinstance(s, str)
> >> True
> >> >>> unicode(s, "gb2312")
> >> u'\u4e2d\u56fd'
> >> >>> s.decode("gb2312")
> >> u'\u4e2d\u56fd'
> >>
> >> µ«ÎÒÔÚtest.pyÖÐÍêÈ«Ò»ÑùÕâôд£¬È´±¨´í£º
> > ÄãµÄ test.py ±¾ÉíµÄ±àÂëÊÇ·ñ utf-8 ?
> >> # -*- coding: utf8 -*-
> >> s = "Öйú"
> >> print s
> >> print isinstance(s, str)
> >> print unicode(s, "gb2312")
> >> print s.decode(s, "gb2312")
> >> ÔËÐнá¹û£º
> >> 中国
> >> True
> >> Traceback (most recent call last):
> >>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
> >>     print unicode(s, "gb2312")
> >> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> >> illegal multibyte s
> >> equence
> >>
> >> ÇëÎÊÕâÊÇΪºÎ£¿
> >>
> >>
> >> ÎÊÌâ2:¹ØÓÚUTF8±àÂ룬ÎÒÔںܶàµØ·½¿´µ½ÊÇÓÃ×Ö·û´®"utf-8"£¬Ò²Óв»Éٵط½ÊÇ
> >> "utf8"£¬Á½ÕßÓв»Í¬Ã´£¿ÎÒ֮ǰºÃÏñ¼ÇµÃ"utf-8"ÔÚ
> >> ʲôÇé¿öÏ»áÓÐÎÊÌâµÄ£¬µ«ÏÖÔÚÒ»ÏÂ×ÓÏë²»ÆðÀ´ÁË¡£
> >>

˵Ã÷Äã¿´µÃ»¹ÊDz»¹»×Ðϸ£¬zoom.quietµÄ»Ø¸´É¢ÂäÔÚÄãµÄÓʼþÖУ¬Òª×Ðϸ¿´¡£

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 13:15

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 13:15:11 HKT 2007

再一行行看看确实漏看了,主要这个>太多了,看晕了,实在抱歉啊各位前辈,还望以后继续不吝赐教啊,拜谢拜谢再拜谢

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of limodou
Sent: 2007年3月5日 11:48 AM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese] 还是两个编码问题

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> 不是吧,我说错什么了?哪里不礼貌了?真是晕了。
> 下面的邮件除了引用无其它回复,我以为Quiet大虾是不是回复邮件的时候弄错了呢,所以才问问他想说什么。
> 哥们你火气好大啊。
>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn 
> [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
> Sent: 2007年3月5日 11:26 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> 别人回复你的问题是出于好意,仔细阅读别人的解答是一种礼貌. Zoom.quiet是这儿的
> 前辈,而且他的解答切中要害,你应该仔细看看,并注意基本的礼貌。这儿没有任何
> 人有义务回答你的任何问题。
>
> On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
> > 除了引用无其它内容,Zoom.quiet你想说什么?
> >
> > -----Original Message-----
> > From: python-chinese-bounces在lists.python.cn
> > [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of 
> > Zoom.Quiet
> > Sent: 2007年3月5日 11:08 AM
> > To: python-chinese在lists.python.cn
> > Subject: Re: [python-chinese] 还是两个编码问题
> >
> > On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> >>
> >>
> >> 问题1:
> >>
> >> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
> > IDLE 中的所有都是 unicode 处理的
> >> >>> # -*- coding: utf8 -*-
> >> >>> s = "中国"
> >> >>> s
> >> '\xd6\xd0\xb9\xfa'
> >> >>> isinstance(s, str)
> >> True
> >> >>> unicode(s, "gb2312")
> >> u'\u4e2d\u56fd'
> >> >>> s.decode("gb2312")
> >> u'\u4e2d\u56fd'
> >>
> >> 但我在test.py中完全一样这么写,却报错:
> > 你的 test.py 本身的编码是否 utf-8 ?
> >> # -*- coding: utf8 -*-
> >> s = "中国"
> >> print s
> >> print isinstance(s, str)
> >> print unicode(s, "gb2312")
> >> print s.decode(s, "gb2312")
> >> 运行结果:
> >> 涓浗
> >> True
> >> Traceback (most recent call last):
> >>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
> >>     print unicode(s, "gb2312")
> >> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> >> illegal multibyte s
> >> equence
> >>
> >> 请问这是为何?
> >>
> >>
> >> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是
> >> "utf8",两者有不同么?我之前好像记得"utf-8"在
> >> 什么情况下会有问题的,但现在一下子想不起来了。
> >>

说明你看得还是不够仔细,zoom.quiet的回复散落在你的邮件中,要仔细看。

--
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月05日 星期一 13:25

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 5 13:25:18 HKT 2007

谢谢Quiet大虾,俺好好看看先 

-----Original Message-----
From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Zoom.Quiet
Sent: 2007年3月5日 11:40 AM
To: python-chinese在lists.python.cn; python-cn在googlegroups.com
Subject: Re: [python-chinese] 还是两个编码问题

On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> 不是吧,我说错什么了?哪里不礼貌了?真是晕了。
> 下面的邮件除了引用无其它回复,我以为Quiet大虾是不是回复邮件的时候弄错了呢,所以才问问他想说什么。
> 哥们你火气好大啊。
是也乎,没有关系,只是表述没有到位,
俺没有在意,就此打住吧;
刚好 http://wiki.woodpecker.org.cn/moin/BPUG/2007-03-03
Alex 有关编码的真空体验可以给些提示,
建议阅读他的Blog 文章,或是录音

>
> -----Original Message-----
> From: python-chinese-bounces在lists.python.cn 
> [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Leira Hua
> Sent: 2007年3月5日 11:26 AM
> To: python-chinese在lists.python.cn
> Subject: Re: [python-chinese] 还是两个编码问题
>
> 别人回复你的问题是出于好意,仔细阅读别人的解答是一种礼貌. Zoom.quiet是这儿的
> 前辈,而且他的解答切中要害,你应该仔细看看,并注意基本的礼貌。这儿没有任何
> 人有义务回答你的任何问题。
>
> On Mon, 05 Mar 2007 11:10:24 +0800, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
>
> > 除了引用无其它内容,Zoom.quiet你想说什么?
> >
> > -----Original Message-----
> > From: python-chinese-bounces在lists.python.cn
> > [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of 
> > Zoom.Quiet
> > Sent: 2007年3月5日 11:08 AM
> > To: python-chinese在lists.python.cn
> > Subject: Re: [python-chinese] 还是两个编码问题
> >
> > On 3/5/07, Deng Patrick-q19285 <kedeng在motorola.com> wrote:
> >>
> >>
> >> 问题1:
> >>
> >> 我在Python 2.5的IDLE 1.2中输入如下语句得到正常结果:
> > IDLE 中的所有都是 unicode 处理的
> >> >>> # -*- coding: utf8 -*-
> >> >>> s = "中国"
> >> >>> s
> >> '\xd6\xd0\xb9\xfa'
> >> >>> isinstance(s, str)
> >> True
> >> >>> unicode(s, "gb2312")
> >> u'\u4e2d\u56fd'
> >> >>> s.decode("gb2312")
> >> u'\u4e2d\u56fd'
> >>
> >> 但我在test.py中完全一样这么写,却报错:
> > 你的 test.py 本身的编码是否 utf-8 ?
> >> # -*- coding: utf8 -*-
> >> s = "中国"
> >> print s
> >> print isinstance(s, str)
> >> print unicode(s, "gb2312")
> >> print s.decode(s, "gb2312")
> >> 运行结果:
> >> 涓浗
> >> True
> >> Traceback (most recent call last):
> >>   File "D:\Work\Workspace\pyserial\src\test.py", line 5, in 
> >>     print unicode(s, "gb2312")
> >> UnicodeDecodeError: 'gb2312' codec can't decode bytes in position 2-3:
> >> illegal multibyte s
> >> equence
> >>
> >> 请问这是为何?
> >>
> >>
> >> 问题2:关于UTF8编码,我在很多地方看到是用字符串"utf-8",也有不少地方是
> >> "utf8",两者有不同么?我之前好像记得"utf-8"在
> >> 什么情况下会有问题的,但现在一下子想不起来了。
> >>
> >> _______________________________________________
> >> 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
> >>
> >
> >
> > --
> > '''Time is unimportant, only life important!
> > http://zoomquiet.org
> > blog在http://blog.zoomquiet.org/pyblosxom/
> > wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
> > scrap在http://floss.zoomquiet.org
> > douban在http://www.douban.com/people/zoomq/
> > ____________________________________
> > Pls. use OpenOffice.org to replace M$ Office.
> >      http://zh.openoffice.org
> > Pls. use 7-zip to replace WinRAR/WinZip.
> >      http://7-zip.org/zh-cn/
> > You can get the truely Freedom 4 software.
> > '''
> > _______________________________________________
> > 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
> _______________________________________________
> 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


--
'''Time is unimportant, only life important!
http://zoomquiet.org
blog在http://blog.zoomquiet.org/pyblosxom/
wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet
scrap在http://floss.zoomquiet.org
douban在http://www.douban.com/people/zoomq/
____________________________________
Pls. use OpenOffice.org to replace M$ Office.
     http://zh.openoffice.org
Pls. use 7-zip to replace WinRAR/WinZip.
     http://7-zip.org/zh-cn/
You can get the truely Freedom 4 software.
'''
_______________________________________________
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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号