A = X > Y ? X : Y

Michal Wallace sabren at manifestation.com
Thu Feb 10 01:23:38 EST 2000


Bob Alexander wrote in message
<00e401bf7332$4aea6ea0$74eb0b18 at stcla1.sfba.home.com>...

>It can't be encapsulated into something that looks like a function call


I betcha it can!... How about this?

###

def  cStyleIIF(condition, iftrue, iffalse):
    if eval(condition):
        return eval(iftrue)
    else:
        return eval(iffalse)


x = 5
y = 20
a = cStyleIIF("x<y", "x", "y")

###

You've got some extra overhead there, but if you really
want to do this on one line without evaluating both options
or using boolean short circuits, it might be worth it... :)

-michal
http://www.sabren.com/






More information about the Python-list mailing list