Python Random Access File

前端 未结 7 2087
借酒劲吻你
借酒劲吻你 2020-12-01 16:10

Is there a Python file type for accessing random lines without traversing the whole file? I need to search within a large file, reading the whole thing into memory wouldn\'t

7条回答
  •  时光取名叫无心
    2020-12-01 17:13

    file objects have a seek method which can take a value to particular byte within that file. For traversing through the large files, iterate over it and check for the value in each line. Iterating the file object does not load the whole file content into memory.

提交回复
热议问题