Re: Some python comments/questions

Jack Jansen (Jack.Jansen@cwi.nl)
Wed, 13 Oct 1993 14:44:48 +0100

Recently, Guido.van.Rossum@cwi.nl said:
> > Note that "f" in both functions is a local variable, so you're not
> > really creating new symbols. You need to "return eval('f')", instead
> > of "return f" in my python version, since "f" is not known to be a
> > local variable statically (you could also do an initial "f = None",
> > to avoid having to "eval('f')").
>
> This illustrates an interesting fine point of Python's eval/exec
> semantics: if exec() introduces a new name in the local namespace, the
> "compiler" can't know about it and any references to it later will
> fail mysteriously (since it actually exists in the dictionary of local
> variables but the generated pseudo code will use a "global variable
> reference" and fail to find it).

I often get bitten by this. Would it be possible to let eval() set
some flag or something whereby either the compiler or the runtime code
would stop accessing local variable the cheap way, but go through the
dictionary instead?

--
Jack Jansen        | If I can't dance I don't want to be part of
Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl