3 ms·
Indeed. I think the API should be either: def load(filepath): return csv.reader(filepath) def main: ... with load(myFilepath) as reader:
by Someone 6y ago
Indeed. I think the API should be either:
def load(filepath):
return csv.reader(filepath)
def main:
...
with load(myFilepath) as reader:
for item in reader:
...
where the CSV reader both opens and closes the file, or
def load(file):
return csv.reader(file)
def main:
...
with open(myFilepath) as file
for item in load(file):
...
where the CSV reader is ignorant about opening or closing anything. If desired, add a method to the first API that takes an open file, but don’t close it if callers do
with load(myOpenFile) as reader:
...