Alex Rivera | Logout

Why doesn't print work in a lambda?

Asked 2010-06-04T00:58:26.900
179

Why doesn't this work?

lambda: print "x"

Is this not a single statement, or is it something else? The documentation seems a little sparse on what is allowed in a lambda...

Edit
Report

1 Answer

29

In cases where I am using this for simple stubbing out I use this:

fn = lambda x: sys.stdout.write(str(x) + "\n")

which works perfectly.

answered 2011-05-25T13:24:09.653

Your Answer