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.