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: > > $ 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.
It wasn't fine with 2.4 either: """ Unlike the memory files implemented by the StringIO module, those provided by this module are not able to accept Unicode strings that cannot be encoded as plain ASCII strings. """ http://docs.python.org/lib/module-cStringIO.html Read the docs... Stefan -- http://mail.python.org/mailman/listinfo/python-list