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

tav tav at espians.com
Mon Mar 9 14:04:23 CET 2009

Hey all,

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:

I originally overloaded the ``with`` keyword, but on Guido's guidance
and responses from many others, switched to the ``using`` keyword.

I explain the idea in detail in this blog article:


It covers everything from why these are useful to a proposal of how
the new ``do`` statement and __do__ function could work.

Please note that the intention of this proposal is not to encourage
iteration with blocks -- Python already does this rather elegantly --
but blocks are very useful for more than just iteration as various
Ruby applications have shown.

Let me know what you think.

My apologies if I've missed something obvious. Thanks!

love, tav

plex:espians/tav | tav at espians.com | +44 (0) 7809 569 369
http://tav.espians.com | http://twitter.com/tav | skype:tavespian

More information about the Python-ideas mailing list