[Python-Dev] PEP 3000 and exec

Jim Jewett jimjjewett at gmail.com
Mon Oct 17 19:06:20 CEST 2005


For communicating with an exec/eval child, once exec
cannot run in the current namespace, I asked that it be
possible to pass a read-only "current view" and to see
a return value.

(Guido):
>... it's probably better to create an empty namespace and
> explicitly copy into it ...

> ... just pick certain things out of the namespace [afterwards]

Yes and no.

If the exec'ed code is well defined (and it needs to be if
security is a concern), then that works well.

For more exploratory code, it can be hard to know what
in advance what the code will need, or to agree on the
names of return variables.

The simplest general API that I can come up with is

"You're allowed to see anything I can" (even if it is
in a nested scope or base class, and I realize that
you *probably* won't need it).

"Return value is whatever you explicitly choose to
return"  (Lisp's "last result" might be even simpler,
but would probably lead to confusion other places.)

-jJ


More information about the Python-Dev mailing list