Yet Another MySQL Problem

Tim Chase python.list at tim.thechases.com
Thu May 27 17:47:39 EDT 2010


On 05/27/2010 03:32 PM, Victor Subervi wrote:
> On Thu, May 27, 2010 at 1:15 PM, Tim Chase wrote:
>>> That should be:
>>>
>>>          ', '.join(['%s'] * len(values)))
>>
>> Or as I've done in the past:
>>
>>   ', '.join('%s' for _ in values)
>
> Huh? Can you describe that underscore to me? Fascinating!

The underscore is a valid variable-name, idiomatically used for 
"I don't care about this", often seen in places like tuple 
assignment:

   a,_,_,d = some_4_element_tuple

So in my above case, it could also have been written as

   ', '.join('%s' for value in values)
   ', '.join('%s' for dont_care_about_the_value in values)

but the "_" idiom means "I'm iterating over 'values' but I'm not 
actually using the values I get from it"

-tkc







More information about the Python-list mailing list