Ahh. It  seems so obvious now. :) <br><br>Thanks, Wesley &amp; Kent!<br><br><br><div><span class="gmail_quote">On 7/5/07, <b class="gmail_sendername">wesley chun</b> &lt;<a href="mailto:wescpy@gmail.com">wescpy@gmail.com</a>
&gt; wrote:</span><blockquote class="gmail_quote" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; margin-left: 0.80ex; border-left-color: #cccccc; border-left-width: 1px; border-left-style: solid; padding-left: 1ex">
On 7/5/07, Kent Johnson &lt;<a href="mailto:kent37@tds.net">kent37@tds.net</a>&gt; wrote:<br>&gt; wc yeee wrote:<br>&gt; &gt; Hi. Is there a reason the code below raises a syntax error? It&#39;s<br>&gt; &gt; probably something silly on my part, but I can&#39;t figure it out:
<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;&nbsp;&nbsp;&gt;&gt;&gt; b = lambda: print(&#39;bar&#39;)<br>&gt; &gt;&nbsp;&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; b = lambda: print(&#39;bar&#39;)<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^
<br>&gt; &gt; SyntaxError: invalid syntax<br>&gt;<br>&gt; The body of a lambda has to be an expression, not a statement. print is<br>&gt; a statement.<br>&gt; &gt;<br>&gt;<br>&gt; &gt; This works fine too:<br>&gt; &gt;<br>
&gt; &gt;&nbsp;&nbsp;&gt;&gt;&gt; import sys<br>&gt; &gt;&nbsp;&nbsp;&gt;&gt;&gt; a = lambda: sys.stdout.write(&#39;foo\n&#39;)<br>&gt; &gt;&nbsp;&nbsp;&gt;&gt;&gt; a()<br>&gt; &gt; foo<br>&gt;<br>&gt; Right, that is an expression and it is the workaround for your original
<br>&gt; problem.<br><br><br>one thing to keep in mind when thinking, &quot;is this an expression or a<br>statement?&quot; is that the former will always evaluate to some sort of<br>Python object (numerical calculation, function return value [your case
<br>above], some string you&#39;ve built, etc.) whereas the latter will not<br>have any kind of intrisic value (print, while, if, class, def... none<br>of these have a &quot;value&quot;).<br><br>on a partially-related note, print will be changing to a function in
<br>the next generation of Python... see PEP 3105:<br><br><a href="http://www.python.org/dev/peps/pep-3105/">http://www.python.org/dev/peps/pep-3105/</a><br><br>for a list of some of the other changes coming down the line:
<br><a href="http://www.python.org/dev/peps/pep-3100/">http://www.python.org/dev/peps/pep-3100/</a><br><br>cheers,<br>-- wesley<br>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<br>&quot;Core Python Programming&quot;, Prentice Hall, (c)2007,2001
<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://corepython.com">http://corepython.com</a><br><br>wesley.j.chun :: <a href="http://wescpy-at-gmail.com">wescpy-at-gmail.com</a><br>python training and technical consulting<br>cyberweb.consulting : silicon valley, ca
<br><a href="http://cyberwebconsulting.com">http://cyberwebconsulting.com</a><br></blockquote></div><br>