In python 2.6, I want to do:
f = lambda x: if x==2 print x else raise Exception() f(2) #should print \"2\" f(3) #should throw an exception <
what you need exactly is
def fun(): raise Exception() f = lambda x:print x if x==2 else fun()
now call the function the way you need
f(2) f(3)