I have this code, and I would like to use the app parameter to generate the code instead of duplicating it.
if app == 'map':
try:
from modulo.map.views import map
return map(request, *args, **kwargs)
except ImportError:
pass
elif app == 'schedule':
try:
from modulo.schedule.views import schedule
return schedule(request, *args, **kwargs)
except ImportError:
pass
elif app == 'sponsors':
try:
from modulo.sponsors.views import sponsors
return sponsors(request, *args, **kwargs)
except ImportError:
pass
elif app == 'streaming':
try:
from modulo.streaming.views import streaming
return streaming(request, *args, **kwargs)
except ImportError:
pass
Do you have any idea ?
Thanks
I would prefer to use the dispatch-dictionary idiom, coding something like…:
Not sure what you think “code generation” would buy you to make it preferable to this kind of approach.