300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Python3实现从txt文件中读取指定行的方法

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

时间:2022-05-14 01:48:31

相关推荐

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

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 linereturn ''the_line = linecache.getline('d:/FreakOut.cpp', 222)print (the_line)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。