This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Holy Red Snakes!
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
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.
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.)