Python天天美味(18) - linecache.getline()读取文件中特定一行
2008-05-10 21:52
706 查看
Python中使用标准库中的linecache中的getline方法可以从某个文件中读取出特定的一行。比如:
import linecache
print linecache.getline('2.1_open.py', 4)
将返回我上一节事例代码文件2.1_open.py的第4行文字,输出结果:
f = open('/home/evergreen/桌面/test')
查看linecache中的实现(我用的是Ulipad,所以直接将光标停留在linecache处,按F6键)
linecache.py
Python 天天美味(17) - open读写文件
Python 天天美味(18) - linecache.getline()读取文件中特定一行
Python 天天美味(19) - 时间处理datetime
Python 天天美味(20) - 命令行参数sys.argv
...
import linecache
print linecache.getline('2.1_open.py', 4)
将返回我上一节事例代码文件2.1_open.py的第4行文字,输出结果:
f = open('/home/evergreen/桌面/test')
查看linecache中的实现(我用的是Ulipad,所以直接将光标停留在linecache处,按F6键)
linecache.py
Python 天天美味系列(总)
Python 天天美味(16) - 过滤字符串的技巧,map与itertools.imapPython 天天美味(17) - open读写文件
Python 天天美味(18) - linecache.getline()读取文件中特定一行
Python 天天美味(19) - 时间处理datetime
Python 天天美味(20) - 命令行参数sys.argv
...
相关文章推荐
- Python linecache.getline()读取文件中特定一行的脚本
- Python linecache.getline()读取文件中特定一行的脚本
- python linecache 模块读取文件
- python 读取文件的最后一行
- Python读取文件中特定位置及特定数目的内容
- python读取CSV文件以及“写入CSV致文件每一行后面会多一个空行”问题解决
- python之文件读取一行一行的方法
- python计算文件的行数和读取某一行内容的实现方法
- Python【读取文件,第一行与最后一行】
- python读取文件中的一行有效数据
- python学习-打开文件并读取用一行表示
- python小工具___读取指定文件中特定字符串存入Excel表格
- python计算文件的行数和读取某一行内容的实现方法
- python linecache模块 快速读取模块某行
- python读取txt文件最后一行(文件大+文件小)
- python计算文件的行数和读取某一行内容的实现方法
- python随机读取文件中的某一行内容
- Python读取文件的一行之linecache模块
- 人生第一份python脚本 ---- 遍历文件夹中文件,删除特定文件中的一行代码