为什么第二个调用:
num_lines = len(file.read().split("\n")) - 1
返回0而不是正确的值?
with open("Data.txt", "r+") as file:
num_lines = len(file.read().split("\n")) - 1
print("Old num_lines: " + str(num_lines))
# Add 10 new lines of data to end of the file
for i in range(num_lines, num_lines + 10):
file.write("{}, {}\n".format(i, random.randint(0, 10)))
num_lines = len(file.read().split("\n")) - 1
print("New num_lines: " + str(num_lines))