2.5中的cStringIO与2.4的行为有什么不同? [英] Any reason why cStringIO in 2.5 behaves different from 2.4?
问题描述
在一小时内搜索XML解析中的潜在错误
(PyXML),在从2.4更新到2.5之后,我发现了这个:
$ python2.5
Python 2.5(release25-maint,2006年12月9日,14:35:53)
[GCC 4.1.2 20061115(预发布)(Debian 4.1.1-20) ] on linux2
输入help,copyright,credit等等。或许可证或欲获得更多信息。
>> import StringIO
x = StringIO.StringIO(u" m \ xf6p")
导入cStringIO
x = cStringIO.StringIO(um \ xf6p")
Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,< module>
UnicodeEncodeError:'' ascii''编解码器不能编码位置1中的字符u''\ xf6'':序数不在范围内(128)
< blockquote class =post_quotes>
>>>
$ python
Python 2.4.4(#2,2007年4月5日,20:11: 18)
[GCC 4.1.2 20061115(预发布)(Debian 4.1.1-21)] on linux2
输入help,copyright, ;学分"或许可证或欲获得更多信息。
>> import StringIO
x = StringIO.StringIO(u" m \ xf6p")
导入cStringIO
x = cStringIO.StringIO(um\xf6p")
好的,这就是为什么我的代码在Python 2.4中运行良好并打破
2.5。
{sigh}
-
网(en): http: //www.no-spoon.de/ - * - Web(de): http ://www.frell.de/
python2.5
Python 2.5(release25- maint,2006年12月9日,14:35:53)
[GCC 4.1.2 20061115(预发布)(Debian 4.1.1-20)]关于linux2
类型& ;帮助","版权"," credit"或许可证或欲获得更多信息。
>> import StringIO
x = StringIO.StringIO(u" m \ xf6p")
导入cStringIO
x = cStringIO.StringIO(um \ xf6p")
Traceback(最近一次调用最后一次):
文件"< stdin>",第1行,< module>
UnicodeEncodeError:'' ascii''编解码器不能编码位置1中的字符u''\ xf6'':序数不在范围内(128)
< blockquote class =post_quotes>
>>>
python
Python 2.4.4(#2,2007年4月5日,20: 11:18)
[GCC 4.1.2 20061115(预发布)(Debian 4.1.1-21)] on linux2
输入help,copyright ,信用或许可证或欲获得更多信息。
>> import StringIO
x = StringIO.StringIO(u" m \ xf6p")
导入cStringIO
x = cStringIO.StringIO(um\xf6p")
好的,这就是为什么我的代码在Python 2.4中运行良好并打破
2.5。
{sigh}
-
网(en): http: //www.no-spoon.de/ - * - Web(de): http ://www.frell.de/
Stefan Scholl写道:
之后小时搜索XML解析中的潜在错误
(PyXML),在从2.4更新到2.5之后,我发现了这个:
After an hour searching for a potential bug in XML parsing
(PyXML), after updating from 2.4 to 2.5, I found this one:
$ python2.5
Python 2.5 (release25-maint, Dec 9 2006, 14:35:53)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>import StringIO
x = StringIO.StringIO(u"m\xf6p")
import cStringIO
x = cStringIO.StringIO(u"m\xf6p")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xf6'' in position 1: ordinal not in range(128)>>>
$ python
Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>import StringIO
x = StringIO.StringIO(u"m\xf6p")
import cStringIO
x = cStringIO.StringIO(u"m\xf6p")
OK, that''s why my code was fine with Python 2.4 and breaks with
2.5.
{sigh}
--
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/解决方案python2.5
Python 2.5 (release25-maint, Dec 9 2006, 14:35:53)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>import StringIO
x = StringIO.StringIO(u"m\xf6p")
import cStringIO
x = cStringIO.StringIO(u"m\xf6p")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: ''ascii'' codec can''t encode character u''\xf6'' in position 1: ordinal not in range(128)>>>
python
Python 2.4.4 (#2, Apr 5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.>>import StringIO
x = StringIO.StringIO(u"m\xf6p")
import cStringIO
x = cStringIO.StringIO(u"m\xf6p")
OK, that''s why my code was fine with Python 2.4 and breaks with
2.5.
{sigh}
--
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/
Stefan Scholl wrote:After an hour searching for a potential bug in XML parsing
(PyXML), after updating from 2.4 to 2.5, I found this one:
这篇关于2.5中的cStringIO与2.4的行为有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!