Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


If you do that, it will try to read from a closed file.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: