使用file.seek()跳到文件中的特定位置。但是,请考虑是否真的有必要再次浏览该文件。也许有更好的选择。
with open(name, 'r+') as file: for line in file: # Do Something with line file.seek(0) for line in file: # Do Something with line, second time

使用file.seek()跳到文件中的特定位置。但是,请考虑是否真的有必要再次浏览该文件。也许有更好的选择。
with open(name, 'r+') as file: for line in file: # Do Something with line file.seek(0) for line in file: # Do Something with line, second time