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