Guido van Rossum wrote:

> At the same time, having to use it as follows:
>
>     for f in with_file(filename):
<         for line in f:
>             print process(line)
>
> is really ugly, so we need new syntax, which also helps with keeping
> 'for' semantically backwards compatible. So let's use 'with', and then
> the using code becomes again this:
>
>     with f = with_file(filename):
>         for line in f:
>            print process(line)

or

    with with_file(filename) as f:
        ...

?

(assignment inside block-opening constructs aren't used in Python today,
as far as I can tell...)

> Finally, I think it would be cool if the generator could trap
> occurrences of break, continue and return occurring in BODY.  We could
> introduce a new class of exceptions for these, named ControlFlow, and
> (only in the body of a with statement), break would raise BreakFlow,
> continue would raise ContinueFlow, and return EXPR would raise
> ReturnFlow(EXPR) (EXPR defaulting to None of course).
>
> So a block could return a value to the generator using a return
> statement; the generator can catch this by catching ReturnFlow.
> (Syntactic sugar could be "VAR = yield ..." like in Ruby.)

slightly weird, but useful enough to be cool.  (maybe "return value" is enough,
though. the others may be slightly too weird...  or should that return perhaps
be a "continue value"?  you're going back to the top of loop, after all).

</F> 



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to