刚刚学python,小白一枚,今天拿python来去除一段代码前面的行号,
待处理文件看起来是这样的001package org.apche.lucene.demo;
002import java.io.BufferedReader;
…
python代码是这么写的(在ipython环境中)
f = open("in")
lines = f.readlines()
fout = open("out", "w")
for line in lines:
fout.write(line[3:])
exit()
结果输出文件当中只有117行代码,而输入文件中明明有239行。
不是很懂其中的原因,考虑过缓冲区未写出的问题,但是exit()之后输出文件仍然只有117行代码。求大神指点,多谢!
Guess: There is a character after line 117 that allows readline() to determine the end of the file
You can add a breakpoint and try it step by step.
You can check len(lines) to see if it is 239.
And I suggest you add
Maybe it’s because in this file, there are more than 100 lines of text with a length less than 3