classification
Title: Add __enter__ and __exit__ methods to StringIO/cStringIO classes
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, loewis, peppergrower
Priority: normal Keywords:

Created on 2008-10-04 11:06 by peppergrower, last changed 2008-10-04 15:49 by benjamin.peterson. This issue is now closed.

Messages (3)
msg74309 - (view) Author: (peppergrower) Date: 2008-10-04 11:06
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?

Thanks,
peppergrower

*
http://groups.google.com/group/comp.lang.python/browse_thread/thread/6bdf65bce431e404/a5dc64f43147f4dd?lnk=gst
msg74310 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-10-04 11:16
Certainly not for 2.5 or 2.6. Targetting this as 2.7.
msg74315 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-10-04 15:49
This is a duplicate of #1286.
History
Date User Action Args
2008-10-04 15:49:25benjamin.petersonsetstatus: open -> closed
resolution: duplicate
messages: + msg74315
nosy: + benjamin.peterson
2008-10-04 11:16:02loewissetnosy: + loewis
messages: + msg74310
versions: + Python 2.7, - Python 2.5
2008-10-04 11:06:10peppergrowercreate