[Python-Dev] Re: anonymous blocks

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Apr 27 02:53:04 CEST 2005


Nick Coghlan wrote:

> def template():
>   # pre_part_1
>   yield None
>   # post_part_1
>   yield None
>   # pre_part_2
>   yield None
>   # post_part_2
>   yield None
>   # pre_part_3
>   yield None
>   # post_part_3
> 
> def user():
>   block = template()
>   with block:
>     # do_part_1
>   with block:
>     # do_part_2
>   with block:
>     # do_part_3

That's an interesting idea, but do you have any use cases
in mind?

I worry that it will be too restrictive to be really useful.
Without the ability for the iterator to control which blocks
get executed and when, you wouldn't be able to implement
something like a case statement, for example.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list