# -*- 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()

python模块之linecache的更多相关文章

  1. Python模块应用 (linecache)

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

  2. Python模块----linecache

    Python标准库提供了一个有趣的模块:linecache模块.该模块用来从文件中读取任何的行,并且将这些lines使用缓存进行优化,常见的情况是从个大文件中读取指定的行.不过由于此模块使用内存进行缓 ...

  3. python模块大全

    python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...

  4. 使用C/C++写Python模块

    最近看开源项目时学习了一下用C/C++写python模块,顺便把学习进行一下总结,废话少说直接开始: 环境:windows.python2.78.VS2010或MingW 1 创建VC工程 (1) 打 ...

  5. Python模块之configpraser

    Python模块之configpraser   一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...

  6. Python模块之"prettytable"

    Python模块之"prettytable" 摘要: Python通过prettytable模块可以将输出内容如表格方式整齐的输出.(对于用Python操作数据库会经常用到) 1. ...

  7. python 学习第五天,python模块

    一,Python的模块导入 1,在写python的模块导入之前,先来讲一些Python中的概念性的问题 (1)模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质是.py ...

  8. windows下安装python模块

    如何在windows下安装python模块 1. 官网下载安装包,比如(pip : https://pypi.python.org/pypi/pip#downloads) pip-9.0.1.tar. ...

  9. 安装第三方Python模块,增加InfoPi的健壮性

    这3个第三方Python模块是可选的,不安装的话InfoPi也可以运行. 但是如果安装了,会增加InfoPi的健壮性. 目录 1.cchardet    自动检测文本编码 2.lxml    用于解析 ...

随机推荐

  1. Error: Program type already present: android.arch.lifecycle.LifecycleRegistry$1

    com.firebaseui:firebase-ui-firestore:3.1.0 depends on android.arch.lifecycle:extensions:1.0.0-beta1. ...

  2. 100base-T

    100Base-T是一种以100Mbps速率工作的局域网(LAN)标准,它通常被称为快速以太网标准,并使用两对UTP(非屏蔽双绞线)铜质电缆. 快速以太网 : 与10BASE-T的区别在于网络速率是1 ...

  3. Centos7 搭建lnmp环境 (centos7+nginx+MySQL5.7.9+PHP7)

    阿里云一台服务器出现问题! 我估计是一键安装包环境的原因,所以打算重新搭建下环境! 首先,当然是先做好快照!安全第一! 对系统盘做更换系统操作,装上纯净版的centos. 装好后,进入系统 一.挂载数 ...

  4. Jquery取得iframe中元素的几种方法(转载)

    iframe在复合文档中经常用到,利用jquery操作iframe可以大幅提高效率,这里收集一些基本操作 DOM方法:父窗口操作IFRAME:window.frames["iframeSon ...

  5. eclipse如何debug调试jdk源码,并显示局部变量

    http://blog.csdn.net/xuefeng0707/article/details/8738869 http://blog.csdn.net/leehsiao/article/detai ...

  6. Python3 比较两个图片是否类似或相同

    Python代码 #coding:utf8 import os from PIL import Image,ImageDraw,ImageFile import numpy import pytess ...

  7. 你应该知道的Linux历史

    说道linux的历史不得不说的就是unix,我们的linux就是类unix系统: 1969年第一台unix系统 贝尔实验室 1970年C语言诞生,对unix内核重新编写 system V(AT& ...

  8. [Docker] Hooking a Volume to Node.js Source Code

    Normally when you create a Volume, it will store in Docket Host, you can also tell the folder which ...

  9. 【Python】使用geocoder找出本机IP所在经纬度和城市

    代码: import geocoder g = geocoder.ip('me') print(g.latlng) # 经纬度 print(g.city) # 所在城市 输出: C:\Users\ho ...

  10. Android 自定义 ListView 上下拉动“刷新最新”和“加载更多”歌曲列表

    本文内容 环境 测试数据 项目结构 演示 参考资料 本文演示,上拉刷新最新的歌曲列表,和下拉加载更多的歌曲列表.所谓"刷新最新"和"加载更多"是指日期.演示代码 ...