[issue7426] StringIO and with statement
Jean-Michel Fauth
report at bugs.python.org
Thu Dec 3 11:12:53 CET 2009
New submission from Jean-Michel Fauth <wxjmfauth at gmail.com>:
When toying with the "with" statement, I fell on this:
Python 2.6.4
>>> with open('abc.txt', 'r') as f:
for line in f:
print line.rstrip()
abc
def
>>>
>>> import StringIO
>>> fo = StringIO.StringIO('abc\ndef\n')
>>> fo.seek(0)
>>> with fo as f2:
for line in f2:
print line.rstrip()
Traceback (most recent call last):
File "<psi last command>", line 2, in <module>
AttributeError: StringIO instance has no attribute '__exit__'
>>>
>>>
Same result with cStringIO
-----
Python 3.1.1
>>> fo = io.StringIO('abc\ndef\n')
>>> fo.seek(0)
0
>>> with fo as f:
for line in f:
print(line.rstrip())
abc
def
>>>
----------
components: None
messages: 95924
nosy: jmfauth
severity: normal
status: open
title: StringIO and with statement
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7426>
_______________________________________
More information about the Python-bugs-list
mailing list