[Python-ideas] More things in the standard library equipped with __enter__ and __exit__

Brett Cannon brett at python.org
Sun Jan 18 23:32:06 CET 2009

On Sun, Jan 18, 2009 at 04:40, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> Hello,
> I have entered this yesterday : http://bugs.python.org/issue4972.
> about the fact that ftplib.FTP could be
> used in a "with" loop.
> But I spotted that imaplib.IMAP4/IMAP4_SSL and smtplib.SMTP could be
> equipped as well,
> so an __exit__ call takes care of closing or quiting.
> This change could be done together with some examples in the documentation.
> If this sounds like a good idea, I can start a patch in #4972,

They should be separate patches, but yes, more context managers are a
good thing (we are not calling them "'with' loops" since they don't
loop =).


More information about the Python-ideas mailing list