zoukankan      html  css  js  c++  java
  • python模块之linecache

    # -*- coding: utf-8 -*-
    #python 27
    #xiaodeng
    #python模块之linecache
    
    
    import linecache
    '''
    >>> help(linecache)
    Help on module linecache:
    FUNCTIONS
        checkcache = extended_linecache_checkcache(filename=None, orig_checkcache=<function checkcache>)
            Extend linecache.checkcache to preserve the <pyshell#...> entries
            
            Rather than repeating the linecache code, patch it to save the
            <pyshell#...> entries, call the original linecache.checkcache()
            (skipping them), and then restore the saved entries.
            
            orig_checkcache is bound at definition time to the original
            method, allowing it to be patched.
        
        clearcache()
            Clear the cache entirely.
        
        getline(filename, lineno, module_globals=None)
    
    DATA
        __all__ = ['getline', 'clearcache', 'checkcache'] 
    '''
    
    
    #从名为filename的文件中得到第lineno行。这个函数从不会抛出一个异常–产生错误时它将返回”(换行符将包含在找到的行里)。
    
    
    
    #linecache.getline(filename,lineno)
    #查找特定行(第一行)的数据,返回一个字符串
    filename='1.txt'
    re= linecache.getline(filename,1)
    print re.strip()#因为本身带有换行符
    
    
    
    #得到所有行数据,返回一个list
    re= linecache.getlines(filename)
    print re
    
    
    
    #获取多少行的数据
    re= linecache.getlines(filename)[0:4]
    print re
    
    
    
    #更新文件名为filename的缓存。如果filename文件更新了,使用这个函数可以更新linecache.getlines(filename)返回的列表
    linecache.updatecache(filename)
    
    
    
    #清理缓存
    linecache.clearcache()
  • 相关阅读:
    Dockerfile
    走进Docker
    liunx 设置定时任务
    《程序员自我修养》读书笔记
    Ubuntu换源
    liunx安装python2.7.12
    预习非数值数据的编码方式
    预习原码补码
    第三章预习
    预习非数值数据的编码方式
  • 原文地址:https://www.cnblogs.com/dengyg200891/p/4986058.html
Copyright © 2011-2022 走看看