您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Python按行读取文件的实现方法【小文件和大文件读取】

2024/10/14 8:22:54发布26次查看
本文实例讲述了python按行读取文件的实现方法。分享给大家供大家参考,具体如下:
小文件:
#coding=utf-8 #author: walker #date: 2013-12-30 #function: 按行读取小文件 all_lines = [] try: file = open('txt.txt', 'r') all_lines = file.readlines() except ioerror as err: print('file error: ' + str(err)) finally: if 'file' in locals(): file.close() for line in all_lines: print(line)
大文件:
#coding=utf-8 #author: walker #date: 2013-12-30 #function: 按行读取大文件 try: file = open('txt.txt', 'r') for line in file: print(line) except ioerror as err: print('file error: ' + str(err)) finally: if 'file' in locals(): file.close()
更多python按行读取文件的实现方法【小文件和大文件读取】。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product