我有這段代碼,我想用app參數來生成代碼而不是重複它。Python:如何執行生成的代碼?
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
你有什麼想法嗎?
感謝
「生成」可能不是要走的路。使用一些內省更安全和簡單。 – Thomas 2010-05-19 18:01:32