<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, Jul 4, 2018 at 12:13 PM Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Jul 04, 2018 at 10:20:35AM -0400, David Mertz wrote:<br>
> Hmmm... I admit I didn't expect quite this behavior. I'm don't actually<br>
> understand why it's doing what it does.<br>
> <br>
> >>> def myfun():<br>
> ...    print(globals().update({'foo', 43}), foo)<br>
<br>
Try it with a dict {'foo': 43} instead of a set :-)</blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I think Chris meant to try it inside a function using locals() rather<span> </span></span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">than globals.</span></blockquote><div><br></div><div>Ah... you say "tomato" I say "raspberry"... set, dict...</div><div><br></div><div>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 :-):</div><div><br></div><div><div><font face="monospace, monospace">>>> def myfun():</font></div><div><font face="monospace, monospace">...    print(locals().update({'foo': 44}), locals().get('foo'))</font></div><div><font face="monospace, monospace">...</font></div><div><font face="monospace, monospace">>>> myfun()</font></div><div><font face="monospace, monospace">None 44</font></div></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div></div>