liuyongjians

导航

 

2013年11月5日

摘要: python的迭代器,只需要实现__iter__跟next()方法就成。例如: def __iter__(self): return self def next(self): result = self.get() if result is StopIteration: raise result return result当迭代到最后无值的时候,会抛出StopIteration异常,不过好些自己的实现函数会去预先处理,不抛此异常例如:it = iter(lst)try: while True: ... 阅读全文
posted @ 2013-11-05 11:47 liuyongjians 阅读(159) 评论(0) 推荐(0)