A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-April/052853.html below:

[Python-Dev] Re: anonymous blocks

[Python-Dev] Re: anonymous blocks [Python-Dev] Re: anonymous blocksReinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Fri Apr 22 19:20:46 CEST 2005
Nick Coghlan wrote:

> Interestingly, with this approach, "for dummy in my_resource()" would still wrap 
> the block of code in the entrance/exit code (because my_resource *is* a 
> generator), but it wouldn't get the try/finally semantics.
> 
> An alternative would be to replace the 'yield None' with a 'break' or 
> 'continue', and create an object which supports the resource protocol and NOT 
> the iterator protocol. Something like:
> 
> def my_resource():
>    print "Hi!"   # Do entrance code
>    continue      # Go on with the contents of the 'with' block
>    print "Bye!"  # Do exit code
> 
> (This is currently a SyntaxError, so it isn't ambiguous in any way)

Oh, it is ambiguous, as soon as you insert a for/while statement in your resource
function and want to call continue in there. Other than that, it's very neat.

Maybe "yield" alone (which is always a SyntaxError) could be used.

Reinhold

-- 
Mail address is perfectly valid!

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4