[Python-de] elif auflösen
Hartmut Goebel
h.goebel at crazy-compilers.com
Mit Apr 21 10:08:31 CEST 2004
Andreas Jung wrote:
> Warum machst Du keine Sprungtabelle:
Wenn man die Funktionen nach den eingabe-Strings (hier tags) benennen
kann, kann man sich die Sprungtabelle sparen. Denn nach Murphy vergisst
man bestimmt, die immer mitzuziehen.
Die folgende Idee habe ich von John Acock ('spark'):
def f_aaa1(...):
...
def f_aaa2(...):
...
def call(name, *args)
# lookup function f_<name> in this module
THIS = inspect.getmodule(call)
func = getattr(THIS, 'f_%s' % op)
func(*args)
--
Regards
Hartmut Goebel
| Hartmut Goebel | We build the crazy compilers |
| h.goebel at crazy-compilers.com | Compiler Manufacturer |