Python的iter函数 - 当我在调用之间更改底层迭代器时会发生什么?

时间:2017-07-20 00:45:52

标签: python python-3.x

我正在使用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?

0 个答案:

没有答案