Re:Specific ways to write better Python (2017)
by ehsankia on Saturday June 20, 2020 @08:23PM
(#23588617)
I'm curious, personally I would just put the file handling inside the function handling the file. Is anything wrong with the following much simpler solution?
Why wouldn't you let the method that deals with the file also own the file pointer, and then the context manager from the with-statement close it whenever the function is done? Instead of having to do some magical stuff to make sure it closes at the right time? Is it to make unittest/mocking easier?
[ Parent
| on HN ]