print statement in lambda expression
brian at sweetapp.com
Sat Feb 2 22:53:23 EST 2002
> I just recently found that I couldn't put a print statement in a
> lambda expression as a binding in Tk. Could someone explain why?
> b1 = Button(frame, text="Message", command=lambda: print
> If I replace print with sys.stdout.write, it works fine. I don't
> follow why.
'print "message"' is an statement, not an expression, and lambda
expressions must be, well, expressions :-)
All function calls are expressions so sys.stdout.write will work.
More information about the Python-list