我有一個.txt文件,我用多行創建。Python 3.2 - readline()跳過源文件中的行
當我使用計數累加器運行for循環時,它跳過了行。
它跳過了頂線,並與第二開始,打印第四,第六,等...
什麼是我失蹤了嗎?
** for your reading pleasure**
def main():
# Open file line_numbers.txt
data_file = open('line_numbers.txt', 'r')
# initialize accumulatior
count = 1
# Read all lines in data_file
for line in data_file:
# Get the data from the file
line = data_file.readline()
# Display data retrieved
print(count, ": ", line)
# add to count sequence
count += 1
我覺得@Shelhammer釘它。我想這是不明顯的,「在」做了一個閱讀。那麼,它的確如此。 – Malvolio