I thank Chris and Serhiy for their helpful comments. I agree with both of you, that a lambda won't be able to give the desired result. However, although flawed the idea was a useful stepping stone for me. Perhaps as "the simplest thing that could possibly work".
I thank Serhiy for saying that >>> with helper(map(open, ['a', 'b', 'c'])) as a, b, c: >>> pass can work. Serhiy suggests https://docs.python.org/3/library/contextlib.html#contextlib.ExitStack >>> with ExitStack() as stack: >>> files = [stack.enter_context(open(fname)) for fname in filenames] A simpler alternative, for the OP's original post, could be: >>> with ExitMap(open, ['a', 'b', 'c']) as a, b, c: >>> pass where ExitMap(*args) is equivalent to helper(map(*args)). Of course, using ExitStack is the easy way to code ExitMap. In any case, I think that Chris, Serhiy and myself agree that the OP's problem is best solved using the capabilities that Python already has. -- Jonathan
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/IMNXPS3XPX3MN7ZMUNH27Q26CEHATCWN/ Code of Conduct: http://python.org/psf/codeofconduct/