Python按行读取文件 学习了:https://www.cnblogs.com/scse11061160/p/5605190.html file = open("sample.txt") for line in file: pass # do something file.close() 学习了:https://blog.csdn.net/ysdaniel/article/details/7970883 去除换行符 for line in file.readlines(): line…
1:readline() file = open("sample.txt") while 1: line = file.readline() if not line: break pass # do somethingfile.close() 一行一行得从文件读数据,显然比较慢: 不过很省内存: 测试读10M的sample.txt文件,每秒大约读32000行: 2:fileinput import fileinput for line in fileinput.input("…
1:readline() file = open("sample.txt") while 1: line = file.readline() if not line: break pass # do somethingfile.close() 一行一行得从文件读数据,显然比较慢: 不过很省内存: 测试读10M的sample.txt文件,每秒大约读32000行: 2:fileinput import fileinput for line in fileinput.input("…