Holy Red Snakes!
Gabriele Renzi wrote in about Guido van Rossum’s PEP #340 Anonymous Block Statements proposal announced today:
Think of PEPs as RCRs in python land. Notice this has just been written and is probably going to change a whole lot, but the core idea is: adding blocks to python.
Notice the great near-to-end phrase: Note: the syntactic extensions to yield make it use very similar to that in Ruby. This is intentional.
I can’t seem to find practical examples, but it appears that the
block..as is the influenced syntax here:
block with_file(filename) as f: for line in f: print process(line)
The above being the example of the non-looping case, much like we use
File.open with a block that closes our file handles. And you can use
yield inside the
with_file definition very much like you do in Ruby.
About Ruby’s influence, Guido says:
I think we’re on to something. And I’m not too proud to say that Ruby has led the way here to some extent (even if Python’s implementation would be fundamentally different, since it’s based on generators, which has some different possibilities and precludes some Ruby patterns.)
Of course. Ahem. You’re all red. All of you.