我正在使用iter函数允许我在我停止的时候继续处理我的列表。据我所知,iter会有效地将列表放入生成器中。
假设我遍历文件夹名称:
self.foldernames = load_a_list_of_folder_names_from_somewhere()
def some_func(self):
for foldername in iter(self.foldernames):
print(foldername)
break
some_func()
#(prints first folder name)
#and I decide that my list of foldernames is now out of date and reload it:
timeout = True
if timeout:
self.foldernames = load_a_list_of_folder_names_from_somewhere()
#what happens when I run some_func again?
some_func()
# (will it start at the beginning of the list again?)
# Is there some way to remember which position I was in the list and continue from there?