On 03/02/2018 09:34 AM, David Mertz wrote:

So right now, I can do these:

    class bind(object):
         def __init__(self, *args):
             self.args = args
         def __enter__(self):
             return self.args[0] if len(self.args)==1 else self.args
         def __exit__(self, *args):
             pass

     >>> with bind(sqrt(2)) as _a:
    ...     print(_a)
    1.4142135623730951

     >>> with bind(sqrt(2), log(2)) as (a, b):
    ...     print(a, b, a+b)
    1.4142135623730951 0.6931471805599453 2.1073607429330403


This would cover 98% of the cases that I would want with the proposed 
statement-local name bindings.

Cool!  But what's the advantage over simple assignment?

--
~Ethan~
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to