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

Calvin Spealman ironfroggy at gmail.com
Tue Mar 10 18:13:09 CET 2009


On Mon, Mar 9, 2009 at 12:39 PM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Mar 9, 2009 at 6:04 AM, tav <tav at espians.com> wrote:
>> I've come up with a way to do Ruby-style blocks in what I feel to be a
>> Pythonic way:
>>
>>  using employees.select do (employee):
>>      if employee.salary > developer.salary:
>>          fireEmployee(employee)
>>      else:
>>          extendContract(employee)
>
> 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)

What would `using` here do that decorating the temp function with
employees.select itself wouldn't do? All you are doing is saying "Pass
this function to this function" which is exactly what decorators
already do.

> --
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy



More information about the Python-ideas mailing list