-1
with open('iter.txt') as f:
try:
while True:
line = next(f)
print(line,end='')
except StopIteration:
pass
按预期工作。 但与
print(line,end='\n')
插入空行。
Iteration is one of Python’s strongest features. At a high level, you might simply view
iteration as a way to process items in a sequence. However, there is so much more that
is possible, such as creating your own iterator objects,
为什么? os.linesep有没有其他选择?
文本文件可能已经结束每一行以'\ N',你就加倍了。 – asongtoruin
如何检查它是否以\ n结尾? – MishaVacic
你想让你的最后一行与'end ='''? – wencakisa