linecache是专门支持读取大文件,而且支持行式读取的函数库。 linecache 预先把文件读入缓存起来,后面如果你访问该文件的话就不再从硬盘读取。对于大文件的读取效率还不错

Help on module linecache:

NAME
    linecache - Cache lines from files.

FILE
    /usr/local/lib/python2.7/linecache.py

MODULE DOCS
    http://docs.python.org/library/linecache

DESCRIPTION
    This is intended to read lines from modules imported -- hence if a filename
    is not found, it will look down the module search path for a file by
    that name.

FUNCTIONS
    checkcache(filename=None)
        Discard cache entries that are out of date.
        (This is not checked upon each call!)
    
    clearcache()
        Clear the cache entirely.
    
    getline(filename, lineno, module_globals=None)

DATA
    __all__ = ['getline', 'clearcache', 'checkcache']
help(linecache)

相关文章:

  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2021-08-29
  • 2021-08-23
  • 2022-12-23
猜你喜欢
  • 2022-01-31
  • 2021-08-24
  • 2022-12-23
  • 2022-02-11
  • 2021-10-15
  • 2023-03-30
相关资源
相似解决方案