B
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
import io
out = io.StringIO()
print('hello', file=out)
....which gives an error:
Traceback (most recent call last):
File "./example.py", line 5, in <module>
print('hello', file=out)
File "/usr/local/lib/python2.6/io.py", line 1487, in write
s.__class__.__name__)
TypeError: can't write str to text stream
....which has me stumped. Why can't it?
-Bill
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
import io
out = io.StringIO()
print('hello', file=out)
....which gives an error:
Traceback (most recent call last):
File "./example.py", line 5, in <module>
print('hello', file=out)
File "/usr/local/lib/python2.6/io.py", line 1487, in write
s.__class__.__name__)
TypeError: can't write str to text stream
....which has me stumped. Why can't it?
-Bill