1 利用python的readlines()函数2113:
[python] view plain copy
fobj = open(r'Ori.Data.txt','r')
for line in fobj.readlines()[1000:]
fobj.close()
2 利用5261 linecache
[python] view plain copy
import linecache
print(linecache.getline(r'D:\z.txt',10))
3 读取10行到13行中的内容4102
[python] view plain copy
lnum = 0
with open('pit.txt', 'r') as fd:
for line in fd:
lnum += 1;
if (lnum >= 10) && (lnum <= 13):
print line
fd.close()
4 求文本的行1653数
[python] view plain copy
fobj = open('Ori_Data.txt','r')
row_len = len(fobj.readlines())
[python] view plain copy
[python] view plain copy
fobj = open(filepath,'r')
data = fobj.read()
fobj.close()
text_len = data.count('\n')