Teaching Programming

Stefan Behnel stefan_ml at behnel.de
Tue May 4 08:33:58 EDT 2010


superpollo, 04.05.2010 13:56:
> Stefan Behnel ha scritto:
>> The question is: why do you have to generate the above code in the
>> first place? Isn't a function enough that does the above?
>
> of course! *but* if i must generate on-the-fly python code that defines
> a function  [...]

Well, could you provide a use case where you have to generate Python code, 
and where normally written code with some kind of parametrisation won't work?

The only thing that currently comes to my mind is a template compiler that 
translates a user provided template into an executable Python program. But 
that should be pretty trivial to do as well. I just remembered this little 
thing on Fredrik's effbot site, which should help here:

http://effbot.org/zone/python-code-generator.htm

Stefan




More information about the Python-list mailing list