On 7/11/07, <b class="gmail_sendername">Dave Kuhlman</b> &lt;<a href="mailto:dkuhlman@rexx.com">dkuhlman@rexx.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Wed, Jul 11, 2007 at 11:03:18AM -0400, John Morris wrote:<br>&gt; I&#39;m editing some code from Mailman and seeing:<br>&gt;<br>&gt; legend = _(&quot;%(hostname)s Mailing Lists&quot;)<br>&gt;<br><br>The outer parentheses are a function call.&nbsp;&nbsp;The underscore
<br>is a name that has a callable as a value, I suppose.&nbsp;&nbsp;I<br>believe that the value of the name underscore is the last<br>expression evaluated, but I&#39;m not sure.</blockquote><div><br>Right... Thanks, I figured it was something like that but it was not something I&#39;d encountered.
<br>so if _ =&nbsp; foo<br>then <br>bar = _(&quot;test&quot;) is equivalent to<br>bar = foo(&quot;test&quot;)<br><br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Mailman is a great product.&nbsp;&nbsp;But that bit of code is not, I think,<br>very good code.&nbsp;&nbsp;In Python explicitness is a virtue, and the use of<br>the underscore is implicit and is not very Pythonic.</blockquote><div><br>Agreed. The _ stuff is reminiscent of Perl&nbsp; $_, @_ and friends. I&#39;d go miles personally to
<br>avoid that usage, personally. <br><br>I have done the whole &#39;import this&#39; and mightily strive to grok it all properly on a regular basis. ;-)<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
By the way, The inner parentheses are a formatting operation.<br>%(x)s will be replaced by the value of x in Example:<br><br>&nbsp;&nbsp; vals = {&#39;animal&#39;: &#39;dog&#39;}<br>&nbsp;&nbsp; &quot;Rover is a big %(animal)s.&quot; % vals<br>
<br>&quot;%(animal)s&quot; will be replaced by &quot;dog&quot;.&nbsp;&nbsp;When you use this form,<br>the value on the right of the formatting operator must be a<br>dictionary.&nbsp;&nbsp;More from the library reference:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;When the right argument is a dictionary (or other mapping type),
<br>&nbsp;&nbsp;&nbsp;&nbsp;then the formats in the string must include a parenthesised mapping<br>&nbsp;&nbsp;&nbsp;&nbsp;key into that dictionary inserted immediately after the &quot;%&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;character. The mapping key selects the value to be formatted from
<br>&nbsp;&nbsp;&nbsp;&nbsp;the mapping. For example:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&gt;&gt;&gt; print &#39;%(language)s has %(#)03d quote types.&#39; % \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&#39;language&#39;: &quot;Python&quot;, &quot;#&quot;: 2}<br>&nbsp;&nbsp;&nbsp;&nbsp;Python has 002 quote types.
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- <a href="http://docs.python.org/lib/typesseq-strings.html">http://docs.python.org/lib/typesseq-strings.html</a></blockquote><div><br>Thanks for this too, though it&#39;s more completeness than I needed (just wondered if _( was &quot;special&quot; usage or what. Kudos on an excellent reply.
<br></div><br></div>So, any really good tutorials on FP and map, filter, zip, lambda ?<br>I&#39;m trying to wrap my mind around those better...<br><br><br>Thanks much!<br>