Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Serhiy Storchaka
31.05.13 12:55, Peter Otten написав(ла): Serhiy Storchaka wrote: 30.05.13 23:46, Skip Montanaro написав(ла): Am I missing something about how io.StringIO works? I thought it was a more-or-less drop-in replacement for StringIO.StringIO. io.StringIO was backported from Python 3. It is a text

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Peter Otten
Serhiy Storchaka wrote: > 30.05.13 23:46, Skip Montanaro написав(ла): >> Am I missing something about how io.StringIO works? I thought it was >> a more-or-less drop-in replacement for StringIO.StringIO. > > io.StringIO was backported from Python 3. It is a text (unicode) stream. > cStringIO.Stri

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-31 Thread Serhiy Storchaka
30.05.13 23:46, Skip Montanaro написав(ла): Am I missing something about how io.StringIO works? I thought it was a more-or-less drop-in replacement for StringIO.StringIO. io.StringIO was backported from Python 3. It is a text (unicode) stream. cStringIO.StringIO is a binary stream and StringI

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-30 Thread Skip Montanaro
> > I would expect io.StringIO to be a match for the io.* stuff in Python > 3. So it should care whether it is a binary stream or a text stream. > Whereas StringIO.StringIO is your good old Python 2 StringIO, which expects > strs. > > On that basis, io.StringIO is a text stream, expecting Unicode >

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-30 Thread Göktuğ Kayaalp
io.StringIO only accepts Unicode input (i.e. u"multibyte string"), while StringIO.StringIO accepts either 8 bit input or unicode input. As you can see in the following excerpt from your traceback, the 'print_list' function creates an 8-bit string, which is then (probably) passed to 'file.write' as

Re: Surprising difference between StringIO.StringIO and io.StringIO

2013-05-30 Thread Cameron Simpson
On 30May2013 15:46, Skip Montanaro wrote: | Consider this quick session (Python 2.7 using the tip of the 2.7 | branch in Mercurial): | | % python2.7 | Python 2.7.5+ (2.7:93eb15779050, May 30 2013, 15:27:39) | [GCC 4.4.6 [TWW]] on linux2 [...] | >>> import io | >>> s2 = io.StringIO() [...] | Fil

Surprising difference between StringIO.StringIO and io.StringIO

2013-05-30 Thread Skip Montanaro
Consider this quick session (Python 2.7 using the tip of the 2.7 branch in Mercurial): % python2.7 Python 2.7.5+ (2.7:93eb15779050, May 30 2013, 15:27:39) [GCC 4.4.6 [TWW]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import traceback >>> >>> import StringIO