(original) (raw)
Hmmm... I admit I didn't expect quite this behavior. I'm don't actually understand why it's doing what it does.
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.
--
>>> def myfun():
... print(globals().update({'foo', 43}), foo)
...
>>> myfun()
Traceback (most recent call last):
File "", line 1, in
File "", line 2, in myfun
TypeError: cannot convert dictionary update sequence element #0 to a sequence
On Wed, Jul 4, 2018 at 9:58 AM Chris Angelico <rosuav@gmail.com> wrote:
On Wed, Jul 4, 2018 at 11:52 PM, David Mertz <mertz@gnosis.cx> wrote:
\> On Wed, Jul 4, 2018 at 3:02 AM Chris Angelico <rosuav@gmail.com> wrote:
\>>
\>> "Assignment is a statement" -- that's exactly the point under discussion.
\>> "del is a statement" -- yes, granted
\>> "function and class declarations are statements" -- class, yes, but
\>> you have "def" and "lambda" as statement and expression equivalents.
\>> "import is a statement" -- but importlib.import\_module exists for a reason
\>>
\>> I'm going to assume that your term "mutating" there was simply a
\>> miswording, and that you're actually talking about \*name binding\*,
\>> which hitherto occurs only in statements. Yes, this is true.
\>
\>
\> Nope, not actually:
\>
\>>>> del foo
\>>>> print(globals().update({'foo':42}), foo)
\> None 42
\>
Try it inside a function though.
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/mertz%40gnosis.cx
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.
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.