python读取大文件的某行_Python按行读取文件的实现方法【小文件和大文件读取】...
本文實例講述了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相關內容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
總結
以上是生活随笔為你收集整理的python读取大文件的某行_Python按行读取文件的实现方法【小文件和大文件读取】...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7系统玩饥荒游戏出现error d
- 下一篇: java链表实现_数据结构——基于jav