hpmor_split/splitSrc/ChapterTimes.py

34 lines
966 B
Python

from csv import reader
class ChapterTimes():
csvreader: reader
header: list
headerindex: list # [chapterid, part, time]
def __init__(self, filename='chapter.csv'):
self.filename = filename
self.emptlast = False
f = open(self.filename, 'r')
self.csvreader = reader(f)
self.header = next(self.csvreader)
self.headerindex = [
self.header.index('chap'),
self.header.index('Part'),
self.header.index('start')
]
def __iter__(self):
return self
def __next__(self):
try:
row = next(self.csvreader)
except StopIteration:
if self.emptlast:
raise StopIteration
print('Python continue after raise StopIteration')
return None
self.emptlast = True
return [None]*len(self.headerindex)
return [row[i] for i in self.headerindex]