On Wed, Jul 4, 2018 at 12:13 PM Steven D'Aprano <st...@pearwood.info> wrote:
> On Wed, Jul 04, 2018 at 10:20:35AM -0400, David Mertz wrote: > > Hmmm... I admit I didn't expect quite this behavior. I'm don't actually > > understand why it's doing what it does. > > > > >>> def myfun(): > > ... print(globals().update({'foo', 43}), foo) > > Try it with a dict {'foo': 43} instead of a set :-) > I think Chris meant to try it inside a function using locals() rather > than globals. Ah... you say "tomato" I say "raspberry"... set, dict... Yeah, typo fixed, it makes more sense. Still, even a `globals().update()` expression is a binding operation. But it works perfectly fine with locals() also :-): >>> def myfun(): ... print(locals().update({'foo': 44}), locals().get('foo')) ... >>> myfun() None 44 -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ 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