[Python-Dev] anonymous blocks

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Apr 21 04:58:07 CEST 2005

Alex Martelli wrote:
> def withfile(filename, mode='r'):
>     openfile = open(filename, mode)
>     try:
>         block(thefile=openfile)
>     finally:
>         openfile.close()
> i.e., let the block take keyword arguments to tweak its namespace

I don't think I like that idea, because it means that from
the point of view of the user of withfile, the name 'thefile'
magically appears in the namespace without it being obvious
where it comes from.

> (but 
> assignments within the block should still affect its _surrounding_ 
> namespace, it seems to me...).

I agree with that much.

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