Dynamically defined functions via exec in imported module

Michele Simionato michele.simionato at gmail.com
Sat Aug 16 10:11:16 EDT 2008


On Aug 16, 4:02 pm, Maric Michaud <ma... at aristote.info> wrote:
> I'd say that everywhere exec/eval are used in a application/function/lib that
> doesn't mean to interpret arbitrary and user provided python code, it is a
> bad usage

Problem is, there are things you cannot do without
exec/eval: for instance look at the implementation of
my own decorator module, which uses eval to
guarantee a good signature for the decorated function.
Probably it could be done without exec, with
bytecode hacks, but I regard fiddling with bytecodes
as something worse than exec itself. I am not
sure if in Python 3.0 the signature object is
powerful enough to do the job, I never had to
time to check how it works.

    Michele Simionato



More information about the Python-list mailing list