[Python-ideas] Ruby-style Blocks in Python Idea

Guido van Rossum guido at python.org
Tue Mar 10 18:07:58 CET 2009


On Mon, Mar 9, 2009 at 10:59 PM, Carl Johnson
<cmjohnson.mailinglist at gmail.com> wrote:
[Guido]
>> Sounds like you might as well write a decorator named @using:
>>
>>  @using(employees.select)
>>  def _(employee):
>>     if employee.salary > developer.salary:
>>         fireEmployee(employee)
>>     else:
>>         extendContract(employee)
>
> I like that (which is why I proposed allowing lambda decorators last
> month), but I'm uncomfortable with how after all is said and done, _
> will either be set to something that's not a callable or to a callable
> that no one is ever supposed to call.

Well, _ is by convention often used as a "throw-away" result. So I am
totally comfortable with this. Or, at least, I am as comfortable with
it as I am with writing

  name, phone, _, _ = record

to unpack a 4-tuple when the last two elements are not needed.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list