Python Random Access File

2019-01-11 19:59发布

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 be possible.

Any types or methods would be appreciated.

7条回答
Luminary・发光体
2楼-- · 2019-01-11 20:21

The File object supports seek but make sure that you open them as binary, i.e. "rb".

You may also wish to use the mmap module for random access, particularly if the data is in an internal format already.

查看更多
登录 后发表回答