Experiences/guidance on teaching Python as a first programming language
Terry Reedy
tjreedy at udel.edu
Wed Dec 18 17:33:49 EST 2013
On 12/18/2013 3:18 AM, Steven D'Aprano wrote:
> We don't know what locals()['spam'] = 42 will do inside a function,
I am mystified that you would write this. Locals() will "Update and
return a dictionary representing the current local symbol table." The
only thing unspecified is the relation between the 'current local symbol
table' and the *dict* that 'represents' it. Given that a dict is
returned, the rest is unambiguous.
> unlike the C case, we can reason about it:
>
> - it may bind 42 to the name "spam";
"somedict['spam'] = 42" will do exactly that.
> - it may raise a runtime exception;
Absolutely not.
> - it may even be a no-op;
Absolutely not.
--
Terry Jan Reedy
More information about the Python-list
mailing list