In python this series of ifs is normally done with a dictionary. Look at capa_module handle_ajax for an example. Also that example handles the case when one of the functions called raises an exception.