if does not evaluate

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Wed Jun 9 00:18:53 CEST 2004

Robert Brewer wrote:
> If your main desire is to code in some other language while still using
> Python, write your own VB-style IIf function:

All the solutions you propose don't work (except the long form).  You 
cannot code an "iif" function.  Test:

def iif(cond, expr1, expr2):
     if cond: return expr1
     return expr2
def foo(x): return iif(x == 0, 0, 1.0/x)

See PEP 308.


More information about the Python-list mailing list