Lazy Method for Reading Big File in Python?

前端 未结 12 1755
谎友^
谎友^ 2020-11-21 06:40

I have a very big file 4GB and when I try to read it my computer hangs. So I want to read it piece by piece and after processing each piece store the processed piece into an

12条回答
  •  名媛妹妹
    2020-11-21 07:00

    i am not allowed to comment due to my low reputation, but SilentGhosts solution should be much easier with file.readlines([sizehint])

    python file methods

    edit: SilentGhost is right, but this should be better than:

    s = "" 
    for i in xrange(100): 
       s += file.next()
    

提交回复
热议问题