鉴于这种:
class DataFromBls:
"""this is a spitout of data in BLS dump"""
def __init__(self, dataSource, yearOfData, inflationAdjusted):
self.dataSource = dataSource
self.yearOfData = yearOfData
self.inflationAdjusted = inflationAdjusted
def printData(self):
for value in self.dataSource:
yield self.dataSource[value]
那么假设x = DataFromBls([2, 3, 5, 6, 6, 7], 2010, "yes")
然后假设将以下内容提供给解释器,
for value in x.printData():
print value
然后我让解释器吐出 5、6、7,然后给我一个 Traceback IndexError:list index out of range
我不明白它是如何超出范围的,或者为什么只有 5 到 7 出
谢谢