Python "with" Keyword in Lambda Functions

How is the Python with keyword expressed in lambda functions? Consider the following:

 def cat (filename): with open(filename, 'r') as f: return f.read() 

Failed to try lambda:

 cat = lambda filename: with open(filename, 'r') as f: return f.read() 
+4
source share
1 answer

lambda_form ::= "lambda" [parameter_list]: expression

You cannot, with is a statement, and lambda returns expressions.

+6
source

All Articles