A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-July/154292.html below:

[Python-Dev] Examples for PEP 572

[Python-Dev] Examples for PEP 572Steven D'Aprano steve at pearwood.info
Wed Jul 4 12:02:47 EDT 2018
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 :-)

> ...
> >>> myfun()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "<stdin>", line 2, in myfun
> TypeError: cannot convert dictionary update sequence element #0 to a
> sequence

I think Chris meant to try it inside a function using locals() rather 
than globals.


> That said, this is a silly game either way.  And even though you CAN
> (sometimes) bind in an expression pre-572, that's one of those perverse
> corners that one shouldn't actually use.

Still, it is sometimes useful to explore scoping issues by using 
globals() and/or locals() to see what happens. But I would really 
hesitate to use them in production unless I was really careful.



-- 
Steve
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4