Iterators : Iter : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Iter »

 

Iterators


class FileList:
    def __init__(self):
        self.ptr = 0
        self.file_list = ["file1""file2""file3""file4" ]
    def __iter__(self):
        self.ptr = 0
        return self
    def next(self):
        if self.ptr == len(self.file_list):
           raise StopIteration
        s = self.file_list[self.ptr]
        self.ptr = self.ptr + 1
        return s

fl = FileList()
for f in fl :
    print f



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Iter