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()
python模块之linecache的更多相关文章
- Python模块应用 (linecache)
linecache linecache是专门支持读取大文件,而且支持行式读取的函数库. linecache 预先把文件读入缓存起来,后面如果你访问该文件的话就不再从硬盘读取.对于大文件的读取效率还不错 ...
- Python模块----linecache
Python标准库提供了一个有趣的模块:linecache模块.该模块用来从文件中读取任何的行,并且将这些lines使用缓存进行优化,常见的情况是从个大文件中读取指定的行.不过由于此模块使用内存进行缓 ...
- python模块大全
python模块大全2018年01月25日 13:38:55 mcj1314bb 阅读数:3049 pymatgen multidict yarl regex gvar tifffile jupyte ...
- 使用C/C++写Python模块
最近看开源项目时学习了一下用C/C++写python模块,顺便把学习进行一下总结,废话少说直接开始: 环境:windows.python2.78.VS2010或MingW 1 创建VC工程 (1) 打 ...
- Python模块之configpraser
Python模块之configpraser 一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...
- Python模块之"prettytable"
Python模块之"prettytable" 摘要: Python通过prettytable模块可以将输出内容如表格方式整齐的输出.(对于用Python操作数据库会经常用到) 1. ...
- python 学习第五天,python模块
一,Python的模块导入 1,在写python的模块导入之前,先来讲一些Python中的概念性的问题 (1)模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质是.py ...
- windows下安装python模块
如何在windows下安装python模块 1. 官网下载安装包,比如(pip : https://pypi.python.org/pypi/pip#downloads) pip-9.0.1.tar. ...
- 安装第三方Python模块,增加InfoPi的健壮性
这3个第三方Python模块是可选的,不安装的话InfoPi也可以运行. 但是如果安装了,会增加InfoPi的健壮性. 目录 1.cchardet 自动检测文本编码 2.lxml 用于解析 ...
随机推荐
- Python集合模块collections
collections collections是Python内建的一个集合模块,提供了许多有用的集合类. namedtuple 我们知道tuple可以表示不变集合,例如,一个点的二维坐标就可以表示成: ...
- 全景分割panopticapi使用
文件解析 参考github:https://github.com/cocodataset/panopticapi 输入图像:
- ASP.NET MVC2之Model Binder
Model Binder在Asp.net MVC中非常简单.简单的说就是你控制器中的Action方法需要参数数据:而这些参数数据包含在HTTP请求中,包括表单上的Value和URL中的参 数等.而Mo ...
- impala 导出CSV 或excel
1.介绍 impala-shell导入导出 参数说明: • -q query (--query=query) 从命令行执行查询,不进入impala-shell • -d default_db (--d ...
- laravel 开启sql调试
打开app\Providers\AppServiceProvider.PHP,在boot方法中添加如下内容 public function boot() { //sql调试 $sql_debug = ...
- 理解MySQL数据库覆盖索引 (转)
http://www.cnblogs.com/zl0372/articles/mysql_32.html 话说有这么一个表: CREATE TABLE `user_group` ( `id` int( ...
- mke2fs 制作ext2文件系统image
方法1: 利用/dev/ram1: linux下有很多ram,我们用ram1,首先把ram1格式化成ext2文件系统[root@gucuiwen babylinux]# sudo mkfs.ext ...
- 准确率,召回率,F值,机器学习分类问题的评价指标
下面简单列举几种常用的推荐系统评测指标: 1.准确率与召回率(Precision & Recall) 准确率和召回率是广泛用于信息检索和统计学分类领域的两个度量值,用来评价结果的质量.其中精度 ...
- vi入门到精通
VI是在Linux命令行下常用的文本编辑工具,在服务配置管理过程中经常用到:vi的常见的使用指南,互联网上随处可见,但仅能满足初学者对文档编辑的需求.这里就我自己在使用过程中通常用到的一些技巧操作方法 ...
- oracle sqlldr使用(导入速度快,但对数据本身的处理功能弱)
oracle sqlldr使用(导入速度快,但对数据本身的处理功能弱) 博客分类: DB.Oracle OracleSQL sqlload.cmd pause sqlldr user/pass@tn ...