StringIO in 2.6 and beyond

Bill McClain 20080915.20.wmcclain at
Wed Dec 10 19:55:10 CET 2008

On 2008-12-10, pruebauno at <pruebauno at> 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=" ", end="\n")
> out = io.StringIO()
> print("hello", file=out)

The example works, but unicode_literals causes problems elsewhere, in optparse
for example. I didn't look into it too closely. I'll probably give up trying
to anticipate 3.0 with 2.6 too closely.

Sattre Press                                      Tales of War                       by Lord Dunsany
info at

More information about the Python-list mailing list