Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: exec and locals Date: Fri, 28 Feb 2014 00:29:35 +1300 Lines: 21 Message-ID: References: <530de8ed$0$29985$c3e8da3$5496439d@news.astraweb.com> <530e8608$0$11113$c3e8da3@news.astraweb.com> <530ec17e$0$11113$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net F9gl0n7DFZ6hqsBApHxzGwItTW8OAx2elxC3DgyJcWmHIyZudt Cancel-Lock: sha1:DLLf/hYJclEkAVu9ISl34ViCMyY= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <530ec17e$0$11113$c3e8da3@news.astraweb.com> Xref: csiph.com comp.lang.python:67137 Steven D'Aprano wrote: > On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote: > >>Why not just use this version all the time? It should work in both 2.x >>and 3.x. > > Because that's yucky. It's an aesthetic thing: when supported, I want the > Python interpreter to manage the context manager. More yucky than wrapping the Py3 version in an exec? To my way of thinking, that cancels out any elegance that might have been gained from using a with-statement. Do you really need to use the context manager at all? Could you just write the try-statement that you would have written in Py2 if you didn't have a context manager? -- Greg