On 7/11/07, <b class="gmail_sendername">Dave Kuhlman</b> <<a href="mailto:dkuhlman@rexx.com">dkuhlman@rexx.com</a>> 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>> I'm editing some code from Mailman and seeing:<br>><br>> legend = _("%(hostname)s Mailing Lists")<br>><br><br>The outer parentheses are a function call. The underscore
<br>is a name that has a callable as a value, I suppose. I<br>believe that the value of the name underscore is the last<br>expression evaluated, but I'm not sure.</blockquote><div><br>Right... Thanks, I figured it was something like that but it was not something I'd encountered.
<br>so if _ = foo<br>then <br>bar = _("test") is equivalent to<br>bar = foo("test")<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. But that bit of code is not, I think,<br>very good code. 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 $_, @_ and friends. I'd go miles personally to
<br>avoid that usage, personally. <br><br>I have done the whole 'import this' 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> vals = {'animal': 'dog'}<br> "Rover is a big %(animal)s." % vals<br>
<br>"%(animal)s" will be replaced by "dog". When you use this form,<br>the value on the right of the formatting operator must be a<br>dictionary. More from the library reference:<br><br> When the right argument is a dictionary (or other mapping type),
<br> then the formats in the string must include a parenthesised mapping<br> key into that dictionary inserted immediately after the "%"<br> character. The mapping key selects the value to be formatted from
<br> the mapping. For example:<br><br> >>> print '%(language)s has %(#)03d quote types.' % \<br> {'language': "Python", "#": 2}<br> Python has 002 quote types.
<br><br> -- <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's more completeness than I needed (just wondered if _( was "special" 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'm trying to wrap my mind around those better...<br><br><br>Thanks much!<br>