有两种情况,
1,文件比较大。
targetLine = "";
lineNo = 0;
while 1:
mLine = file.read()line();
if not mLine:
break;
lineNo += 1;
if (linecount == lineNO):
targetLine = mLine;
2, 文件比较小
targetLine = "";
mLines = file.read();
targetLine = mLines[-1];
filelineno( )
Return the line number in the current file. Before the first line has been read, returns 0. After the last line of the last file has been read, returns the line number of that line within the file.
readline一行一行的找,找到了再readline一次就可以了
import re
re.sub('\n','',string)
忽略掉换行
line是个什么东西?
line = "a\nb"
s = "a\n"
idx = line.find(s)
line[idx + len(s): line.find('\n', idx + len(s))]