[New-bugs-announce] [issue4039] Add __enter__ and __exit__ methods to StringIO/cStringIO classes

peppergrower report at bugs.python.org
Sat Oct 4 13:06:33 CEST 2008

New submission from peppergrower <mjjohnson.geo at yahoo.com>:

Currently, StringIO objects do not have __enter__ and __exit__ methods
associated with them.  As a result, the 'with' statement won't work
properly on StringIO objects in a construction like the following,
though they can otherwise be manipulated like files:

with obj.open_file(...) as f:

(I brought up this behavior first on comp.lang.python,* and the above
example was borrowed from Hrvoje Niksic.)  To allow StringIO objects to
be used more interchangeably with actual file objects, could __enter__
and __exit__ methods be added?



components: Interpreter Core
messages: 74309
nosy: peppergrower
severity: normal
status: open
title: Add __enter__ and __exit__ methods to StringIO/cStringIO classes
type: feature request
versions: Python 2.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list