News for hackers. Stuff that matters.
Re:Specific ways to write better Python (2017) by ehsankia on Saturday June 20, 2020 @08:25PM (#23588623)
Why not just have the with-statement/filehandler inside `judgments_from_file`? You're doing all sorts of messy stuff to make sure the file closes whenever `judgments_from_file` is done, wouldn't it make sense to just have it control the lifecycle of the file?

The only reason I can think of to do it the other way is if you want to make unit testing easier, allowing you to pass a fake iterable instead of a file pointer to `judgments_from_file` for testing.

Re:Specific ways to write better Python (2017) by softwaredoug on Saturday June 20, 2020 @09:07PM (#23588827)
I think that’s also valid...

What you’re describing is more or less what judgments_open does. I just did it with a context manager. But you’re right there are other ways to safely manage the files lifetime.

I also use this pattern for writing judgments, which has work to do when done judgments are all collected and the context exits.