Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Feb 19 07:00:17 CET 2010


On Fri, 19 Feb 2010 18:52:20 +1300, Gregory Ewing wrote:

> The Ruby approach has the advantage of making it possible to implement
> user-defined control structures without requiring a macro facility. You
> can't do that in Python.
[...] 
> Also, most people who advocate adding some form of block-passing
> facility to Python don't seem to have thought through what would happen
> if the block contains any break, continue, return or yield statements.

That is the only time I ever wanted blocks: I had a series of functions 
containing for loops that looked something vaguely like this:

for x in sequence:
    code_A
    try:
        something
    except some_exception:
        code_B

where code_B was different in each function, so I wanted to pull it out 
as a code block and do this:


def common_loop(x, block):
    code_A
    try:
        something
    except some_exception:
        block

for x in sequence:
    common_loop(x, block)


The problem was that the blocks contained a continue statement, so I was 
stymied.


-- 
Steven



More information about the Python-list mailing list