How best to dynamically define methods (and functions)?

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Sun Sep 2 10:46:37 CEST 2007


Kenneth McDonald wrote:

> I can see an obvious but hacky way to define a Python function at
> runtime. 

What way is this? All Python function definitions in your code are
executed at runtime.

> In case it's of interest in the context of the question, I need to
> define a largish set of functions (and similar methods) that
> define a XML-type markup language. Most of these functions will
> just be of the form
> 
> def fun(...):
>     return Node('fun', ...)
> 
> so it'd definitely be nice to just create most of them
> automatically, and only do the special cases by hand.

This looks cumbersome to me. If you reworked the interface (perhaps
using dicts or a generic function) it might get clearer.

Regards,


Björn

-- 
BOFH excuse #241:

_Rosin_ core solder? But...




More information about the Python-list mailing list