-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