An idiom for code generation with exec
eliben
eliben at gmail.com
Fri Jun 20 15:37:09 EDT 2008
> FWIW, when I had a similar challenge for dynamic coding, I just
> generated a py file and then imported it. This technique was nice
> because can also work with Pyrex or Psyco.
>
I guess this is not much different than using exec, at the conceptual
level. exec is perhaps more suitable when you really need just one
function at a time and not a whole file of related functions.
> Also, the code above can be simplified to: get_counter = lambda
> packet: packet[5:1:-1]
>
OK, but that was just a demonstration. The actual functions are
complex enough to not fit into a single expression.
Eli
More information about the Python-list
mailing list