博客
关于我
Python3实现从txt文件中读取指定行的方法
阅读量:348 次
发布时间:2019-03-04

本文共 373 字,大约阅读时间需要 1 分钟。

Python3实现从txt文件中读取指定行的方法

 
本文实例讲述了Python3实现从文件中读取指定行的方法。分享给大家供大家参考。具体实现方法如下:
 
def getline(the_file_path, line_number):    if line_number < 1:        return ''    for cur_line_number, line in enumerate(open(the_file_path, 'rU')):        if cur_line_number == line_number-1:            return line    return ''the_line = linecache.getline('d:/FreakOut.cpp', 222)print (the_line)

转载地址:http://fhgq.baihongyu.com/

你可能感兴趣的文章
mysql对同一张表进行查询和赋值更新
查看>>
mysql导入数据库出现:Incorrect string value: '\xE7\x82\xB9\xE9\x92\x9F' for column 'chinese' at row 1...
查看>>
mysql导入(ibd文件)
查看>>
Mysql工作笔记006---Mysql服务器磁盘爆满了_java.sql.SQLException: Error writing file ‘tmp/MYfXO41p‘
查看>>
MySQL工具1:mysqladmin
查看>>
mysql常用命令
查看>>
MySQL常用命令
查看>>
mysql常用命令
查看>>
MySQL常用指令集
查看>>
mysql常用操作
查看>>
MySQL常用日期格式转换函数、字符串函数、聚合函数详
查看>>
MySQL常见架构的应用
查看>>
MySQL常见的三种存储引擎(InnoDB、MyISAM、MEMORY)
查看>>
MySQL常见约束条件
查看>>
MySQL常见错误
查看>>
MySQL常见错误分析与解决方法总结
查看>>
mysql并发死锁案例
查看>>
MySQL底层概述—1.InnoDB内存结构
查看>>
MySQL底层概述—2.InnoDB磁盘结构
查看>>
MySQL底层概述—3.InnoDB线程模型
查看>>