Re: StringIO in 2.6 and beyond

2008-12-10 Thread Bill McClain
On 2008-12-10, ajaksu [EMAIL PROTECTED] wrote: On Dec 9, 5:24 pm, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x unmarked string literals are bytestrings. In Python 3.x they're Unicode. The intention is to make the transition from 2.x

Re: StringIO in 2.6 and beyond

2008-12-10 Thread Jean-Paul Calderone
On 10 Dec 2008 11:58:37 GMT, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-10, ajaksu [EMAIL PROTECTED] wrote: On Dec 9, 5:24 pm, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x unmarked string literals are bytestrings. In Python 3.x

Re: StringIO in 2.6 and beyond

2008-12-10 Thread pruebauno
On Dec 10, 6:58 am, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-10, ajaksu [EMAIL PROTECTED] wrote: On Dec 9, 5:24 pm, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x unmarked string literals are bytestrings. In Python 3.x

Re: StringIO in 2.6 and beyond

2008-12-10 Thread pruebauno
On Dec 10, 10:06 am, [EMAIL PROTECTED] wrote: On Dec 10, 6:58 am, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-10, ajaksu [EMAIL PROTECTED] wrote: On Dec 9, 5:24 pm, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x

Re: StringIO in 2.6 and beyond

2008-12-10 Thread Bill McClain
On 2008-12-10, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I think this combination might do the trick (I don't have 2.6 to test it right now): from __future__ import print_function from __future__ import unicode_literals from functools import partial import io print = partial(print, sep=

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Bill McClain
On 2008-12-08, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-08, Christian Heimes [EMAIL PROTECTED] wrote: In this context 'str' means Python 3.0's str type, which is unicode in 2.x. Please report the misleading error message. So this is an encoding problem? Can you give me a hint on

Re: StringIO in 2.6 and beyond

2008-12-09 Thread pruebauno
On Dec 9, 11:28 am, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-08, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-08, Christian Heimes [EMAIL PROTECTED] wrote: In this context 'str' means Python 3.0's str type, which is unicode in 2.x. Please report the misleading error message.

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Bill McClain
On 2008-12-09, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: This puzzles me too. According to the documentation StringIO accepts both byte strings and unicode strings. Try to replace output.write('First line.\n') with output.write(unicode('First line.\n')) or output.write(str('First

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Peter Otten
Bill McClain wrote: I've just installed 2.6, had been using 2.4. This was working for me: #! /usr/bin/env python import StringIO out = StringIO.StringIO() print out, 'hello' I used 2to3, and added import from future to get: #! /usr/bin/env python from

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Bill McClain
On 2008-12-09, Peter Otten [EMAIL PROTECTED] wrote: out = io.StringIO() print(uhello, file=out, end=u\n) out.getvalue() u'hello\n' That has the benefit of working. Thank you! That can't be the intended behavior of print(), can it? Insering non-unicode spaces and line terminators? I

Re: StringIO in 2.6 and beyond

2008-12-09 Thread MRAB
Bill McClain wrote: On 2008-12-09, Peter Otten [EMAIL PROTECTED] wrote: out = io.StringIO() print(uhello, file=out, end=u\n) out.getvalue() u'hello\n' That has the benefit of working. Thank you! That can't be the intended behavior of print(), can it? Insering non-unicode spaces and line

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Bill McClain
On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x unmarked string literals are bytestrings. In Python 3.x they're Unicode. The intention is to make the transition from 2.x to 3.x easier by adding some features of 3.x to 2.x, but without breaking backwards compatibility (not

Re: StringIO in 2.6 and beyond

2008-12-09 Thread Peter Otten
Bill McClain wrote: On 2008-12-09, Peter Otten [EMAIL PROTECTED] wrote: out = io.StringIO() print(uhello, file=out, end=u\n) out.getvalue() u'hello\n' That has the benefit of working. Thank you! That can't be the intended behavior of print(), can it? Insering non-unicode spaces

Re: StringIO in 2.6 and beyond

2008-12-09 Thread ajaksu
On Dec 9, 5:24 pm, Bill McClain [EMAIL PROTECTED] wrote: On 2008-12-09, MRAB [EMAIL PROTECTED] wrote: In Python 2.x unmarked string literals are bytestrings. In Python 3.x they're Unicode. The intention is to make the transition from 2.x to 3.x easier by adding some features of 3.x to 2.x,

StringIO in 2.6 and beyond

2008-12-08 Thread Bill McClain
I've just installed 2.6, had been using 2.4. This was working for me: #! /usr/bin/env python import StringIO out = StringIO.StringIO() print out, 'hello' I used 2to3, and added import from future to get: #! /usr/bin/env python from __future__ import print_function

Re: StringIO in 2.6 and beyond

2008-12-08 Thread Christian Heimes
Bill McClain wrote: I've just installed 2.6, had been using 2.4. This was working for me: #! /usr/bin/env python import StringIO out = StringIO.StringIO() print out, 'hello' I used 2to3, and added import from future to get: #! /usr/bin/env python from __future__

Re: StringIO in 2.6 and beyond

2008-12-08 Thread Bill McClain
On 2008-12-08, Christian Heimes [EMAIL PROTECTED] wrote: In this context 'str' means Python 3.0's str type, which is unicode in 2.x. Please report the misleading error message. So this is an encoding problem? Can you give me a hint on how to correct in my example? I see that io.StringIO() has