Search This Blog

python: return inside with block

if returns value inside with statement, will the file be closed eventually?
The answer is YES

with open('myfile.txt') as f:
return [line for line in f if len(line)>80]

No comments:

Post a Comment