Is there something similar to ?: operator (C/C++) in Python?
gsakkis at rutgers.edu
Sun Jun 19 18:55:27 CEST 2005
"Bo Peng" wrote:
> Roy Smith wrote:
> > Can you give us some idea of what it is that you're trying to do? It pretty unusual to see
> > a requirement like that.
> def func(type_of_obj1, type_of_obj2, .....):
> callfunc( [
> type_of_obj1 and obj1a() or obj1b(),
> type_of_obj2 and obj2a() or obj2b(),
> callfunc can take arbitrary number of objects whose types are determined
> by type_of_obj1 etc.
Unless the obj_i_a and obj_i_b are totally unrelated (very unlikely), I
think this might/should be refactored so that the decision between each
obj_i_a and obj_i_b is done in a separate obj_i_factory callable. If
you provide an example or two of specific triples (type_of_obj_i,
obj_i_a, obj_i_b), we'll have a better idea of whether factories are an
overkill in this case or not.
More information about the Python-list