class Parse(object):
    """A generator that iterates through a CC-CEDICT formatted file, returning
    a tuple of parsed results (Traditional, Simplified, Pinyin, English)"""

def __init__(self, path):
    self.path = path

def __is_comment(self, line):
    return line.startswith('#')

def __iter__(self):
    with open(self.path) as f:
        for line in f:
            if self.__is_comment(line):
                continue
working = line.rstrip().split(' ')
trad, simp = working[0], working[1]
working = ' '.join(working[2:]).split(']')
pinyin = working[0][1:]
english = working[1][1:]
yield trad, simp, pinyin, english
Пользовательский итератор Python: закрытие файла в StopIteration