3 ms·
Swap the square brackets for parentheses in the return statement and it will return a generator expression. That will read the file as needed (ie as you iterat
by KMnO4 3y ago
Swap the square brackets for parentheses in the return statement and it will return a generator expression.
That will read the file as needed (ie as you iterate over it) instead of loading the entire thing in memory.
for record in read_portfolio(fn):
# do stuff
- tomn 3y agoIf you do that, it will try to read from a closed file.