Python开发--linecache
来源:互联网 发布:怎么注册野火软件 编辑:程序博客网 时间:2024/05/21 22:37
转载自http://www.cnblogs.com/hongten/p/hongten_python_linecache.html
#从linecache的名称,我们可以知道该模块和cache(缓存)有关#linecache现把文件读入到缓存中,在以后访问文件的时候,就不必要再从硬盘读取#所以经常用于那些读取频率很高的文件还可以参考:open()
================================================
代码部分:
================================================
#python linecache
#从linecache的名称,我们可以知道该模块和cache(缓存)有关
#linecache现把文件读入到缓存中,在以后访问文件的时候,就不必要再从硬盘读取
#所以经常用于那些读取频率很高的文件
import os
import linecache
def get_content(path):
'''读取缓存中文件的内容,并以字符串形式返回'''
if os.path.exists(path):
content = ''
cache_data = linecache.getlines(path)
for line in range(len(cache_data)):
content += cache_data[line]
return content
else:
print('the path [{}] is not exist!'.format(path))
def main():
path = 'c:\\test.txt'
content = get_content(path)
print(content)
if __name__ == '__main__':
main()
- Python开发--linecache
- [Python]linecache
- Python linecache、glob模块
- Python之linecache模块
- python linecache pachage
- Python linecache模块
- python linecache读取过程
- Python:linecache库
- python linecache 模块读取文件
- python linecache模块使用心得
- python读取文件指定行(linecache模块)
- python读取文件指定行(linecache模块)
- python linecache标准库基础学习
- python读取文件指定行(linecache模块)
- python linecache 处理固定格式文本数据
- 详解python linecache模块读取文件的方法
- python--用linecache模块方便提取文本数据
- 详解python linecache模块读取文件的方法
- IOS开发中(null)与<null>的处理
- python开发--pickle
- Linux文件共享samba
- GIS平台发展方向
- 拓扑排序
- Python开发--linecache
- php-spider代码使用
- 在JSP页面只获取时分秒的问题
- iOS开发中NSDictionary操作大全
- leetcode数据库sql之Department Top Three Salaries
- 解决在使用request得到属性的空指针问题
- Office使用技巧
- Python开发--glob
- CF_148D_BagOfMice