On Wed, Jun 27, 2018 at 7:19 PM, Steven D'Aprano <st...@pearwood.info> wrote:
> On Wed, Jun 27, 2018 at 05:52:16PM +1000, Chris Angelico wrote:
>
>> def test():
>>     a = 1
>>     b = 2
>>     vars = {key: locals()[key] for key in locals()}
>>     return vars
>>
>> What would your intuition say? Should this be equivalent to dict(locals()) ?
>
> That example is so elegant it makes me want to cry.
>
> And not just because you shadowed the vars() builtin *wink*

It gets funnier with nested loops. Or scarier. I've lost the ability
to distinguish those two.

def test():
    spam = 1
    ham = 2
    vars = [key1+key2 for key1 in locals() for key2 in locals()]
    return vars

Wanna guess what that's gonna return?

ChrisA
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to