I've been experimenting with the 'with' statement (in __future__), and
so far I like it. However, I can't get it to work with a cStringIO
object. Here's a minimum working example:
###
from __future__ import with_statement
import cStringIO
teststring='thi s is a test'
with cStringIO.Strin gIO(teststring) as testfile:
pass
###
I get the following error message:
Traceback (most recent call last):
File "testfile.p y", line 6, in <module>
with cStringIO.Strin gIO(teststring) as testfile:
AttributeError: 'cStringIO.Stri ngI' object has no attribute '__exit__'
So, I'm guessing you can't use the 'with' statement with cStringIO
objects? Is this a bug, or do I need to use the 'with' statement
differently to get this to work?
Thanks,
peppergrower
so far I like it. However, I can't get it to work with a cStringIO
object. Here's a minimum working example:
###
from __future__ import with_statement
import cStringIO
teststring='thi s is a test'
with cStringIO.Strin gIO(teststring) as testfile:
pass
###
I get the following error message:
Traceback (most recent call last):
File "testfile.p y", line 6, in <module>
with cStringIO.Strin gIO(teststring) as testfile:
AttributeError: 'cStringIO.Stri ngI' object has no attribute '__exit__'
So, I'm guessing you can't use the 'with' statement with cStringIO
objects? Is this a bug, or do I need to use the 'with' statement
differently to get this to work?
Thanks,
peppergrower
Comment