# -*- 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. HTML5 本地文件操作之FileSystemAPI整理(二)

    一.文件目录操作 1.DirectoryEntry对象 属性: 1.isFile: 操作对象的是否为文件,DirectoryEntry对象固定其值为false 2.isDirectory: 操作对象是 ...

  2. Java(C#)基础差异-语法

    1.long类型 Java long类型,若赋值大于int型的最大值,或小于int型的最小值,则需要在数字后加L或者l,表示该数值为长整数,如long num=2147483650L. 举例如下: p ...

  3. Java工程师成神之路~(2018修订版)

    针对本文,博主最近在写<成神之路系列文章> ,分章分节介绍所有知识点.欢迎关注. 主要版本 更新时间 备注 v1.0 2015-08-01 首次发布 v1.1 2018-03-12 增加新 ...

  4. YAML文件简介

    编程免不了要写配置文件,怎么写配置也是一门学问. YAML 是专门用来写配置文件的语言,非常简洁和强大,远比 JSON 格式方便. 本文介绍 YAML 的语法,以 JS-YAML 的实现为例.你可以去 ...

  5. 【UOJ Round #1】

    枚举/DP+排列组合 缩进优化 QAQ我当时一直在想:$min\{ \sum_{i=1}^n (\lfloor\frac{a[i]}{x}\rfloor + a[i] \ mod\ x) \}$ 然而 ...

  6. linux上安装wps办公软件

    在rhel6.3上安装 金山WPS rpm包时,容易出现出现错误wps Requires: libstdc++.so.6(GLIBCXX_3.4.14).即使安装成功,也不能够使用,只是缺少了一个li ...

  7. Pytorch 0.3加载0.4模型及其之间版本的变化

    1. 0.4中使用设备:.to(device) 2. 0.4中删除了Variable,直接tensor就可以 3. with torch.no_grad():的使用代替volatile:弃用volat ...

  8. ASP,ASP.net,JSP语法、内置对象对比

    1 各自的HelloWord版本 1.1 ASP <%  Response.Write("hello asp") %> 文件名为test.asp. 1.2 ASP.ne ...

  9. C# 二种方法控制系统音量/麦克风大小

    场景:在做播放设备的时候需要控制音量的大小,下面几种方法将满足你的要求 方法一: 改变系统音量设置 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

  10. 提高sql2005中带freetexttable和rank的全文检索的速度

    原来使用中的sql2005的全文检索的速度总是不如意,尤其是带rank的.今天搜了一下,原来在freetexttable中还有一个参数top_n_by_rank,是第4个参数.注意还要设置:EXEC ...