An idiom for code generation with exec
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Jun 20 03:17:23 EDT 2008
eliben a écrit :
> Hello,
>
> In a Python program I'm writing I need to dynamically generate
> functions[*]
(snip)
> [*] I know that each time a code generation question comes up people
> suggest that there's a better way to achieve this, without using exec,
> eval, etc.
Just to make things clear: you do know that you can dynamically build
functions without exec, do you ?
> But in my case, for reasons too long to fully lay out, I
> really need to generate non-trivial functions with a lot of hard-coded
> actions for performance.
Just out of curiousity : could you tell a bit more about your use case
and what makes a simple closure not an option ?
> And there's no problem of security
> whatsoever. If someone is very interested in the application, I will
> elaborate more.
More information about the Python-list
mailing list