3 ms·
Or you can go the other way and force the caller of the load function to ensure that the iterator is closed Pass the responsibility as far up as required. Make
by compressedgas 6y ago
Or you can go the other way and force the caller of the load function to ensure that the iterator is closed
Pass the responsibility as far up as required. Make the `load` function return a context manager. So any use of load would be like:
with load(x) as it:
pass
`load` could be written with `contextlib.contextmanager` as:
@contextlib.contextmanager
def load(filepath):
with open(filepath) as f:
yield csv.reader(f)