Is there something similar to ?: operator (C/C++) in Python?
Bo Peng
bpeng at rice.edu
Sun Jun 19 12:20:30 EDT 2005
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. I was using a bunch of if/else to create objects
and pass them to callfunc.
Since type_of_obj1 etc are usually binary and obj1a() etc will never be
false, the and/or solution does not look so bad in this case.
Thanks.
Bo
More information about the Python-list
mailing list