print statement in lambda expression
gerson.kurz at t-online.de
Sun Feb 3 05:08:49 CET 2002
On Sun, 03 Feb 2002 03:14:53 GMT, "Michael P. Soulier"
<msoulier at mcss.mcmaster.ca_.nospam> wrote:
> Hello people.
> 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?
The reason was explained already by other people, here is a hack that
makes it work nonetheless: use sys.stdout.write; e.g.
lambda x,y: return sys.stdout.write("...")
if you need multiple args, make a varargs output function:
print " ".join(map(str,x))
f = lambda x,y: out(x,y)
More information about the Python-list