4 ms·
> The articles solution makes lifetime of the generator more explicit. Does it? What's the difference between these two snippets? with judgments_open('ju
by carapace 6y ago
> The articles solution makes lifetime of the generator more explicit.
Does it? What's the difference between these two snippets?
with judgments_open('judgments.txt') as judgments
gather_features(judgments)
with open('judgments.txt') as f:
gather_features(judgments_from_file(f))
You still have to complete all the work within the scope of the context manager either way, right?
The code ehsankia presented combines the generator with a closure that includes
the context manager, and automatically carries the scope of the context manager
along with it, so that when the generator is exhausted the context manager's
scope also ends.