快速统计文本文件中的行数( StreamReader.ReadLine() ): 测试代码如下: //读取txt文件中总行数的方法 public static int requestMethod(String _fileName) { Stopwatch sw = new Stopwatch(); var path = _fileName; ; //按行读取 sw.Restart(); using (var sr = new StreamReader(path)) { var ls = "&qu
s = [] f = open('querylist.txt','r') #由于我使用的pycharm已经设置完了路径,因此我直接写了文件名 for lines in f: ls = lines.strip('\n').replace(' ','').replace('.','/').replace('?','').split('/') for i in ls: s.append(i) f.close() print(s) ===================
Python读取txt文件,有两种方式: (1)逐行读取 data=open("data.txt") line=data.readline() while line: print line line=data.readline() (2)一次全部读入内存 data=open("data.txt") for line in data.readlines(): print line