print statement in lambda expression
Brian Quinlan
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?
>
> ie.
>
> b1 = Button(frame, text="Message", command=lambda: print
"message")
>
> 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.
Cheers,
Brian
More information about the Python-list
mailing list