How is Python's with keyword expressed in a lambda function? Consider the following:
def cat (filename):
with open(filename, 'r') as f:
return f.read()
A failed attempt at a lambda implementation:
cat = lambda filename: with open(filename, 'r') as f: return f.read()
open(filename).read()is executed, because the file object is immediately garbage collected. This is an expression and could be used in a lambda. But this is poor style and not a good use case for lambda anyway, using thedefis better.open(filename).read()wherever it was needed?