read file memoryerror

读取文件代码:

lines=file("myfile.txt").read().split("\n")

分析:文件过大,不能一次性读入内存

解决方法:

with open("myfile.txt") as myfile:
    for line in myfile:
        do_something(line.rstrip("\n"))

posted @ 2022-11-13 22:36  dlhl  阅读(39)  评论(0)    收藏  举报