block scope?
Paul Rubin
http
Sat Apr 7 22:33:05 EDT 2007
aleax at mac.com (Alex Martelli) writes:
> >>> locals['x']=5
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: 'builtin_function_or_method' object does not support item
> assignment
Whoops, yeah, meant "locals()['x'] = 5".
> I think that ideally there should be a runtime error when assigning an
> item of locals() with a key that's not a local variable name (possibly
> excepting functions containing exec, which are kind of screwy anyway).
I have no opinion of this, locals() has always seemed like a crazy
part of the language to me and I never use it. I'd be happy to see it
gone since it makes compiling a lot easier.
More information about the Python-list
mailing list