Pythonでイテレータの復習
>>> class Foo: def __init__(self): self.count = 0 def __iter__(self): return self def next(self): self.count += 1 if self.count > 5: raise StopIteration return self.count >>> for x in Foo(): print x 1 2 3 4 5
« VMWareと間欠的なディスクアクセスの関係 |Main| 日記 »
« Subversionへの新規importをちょっと楽にするスクリプト | Python | Pythonでワンライナーを作成する際のノウハウ集 »
>>> class Foo: def __init__(self): self.count = 0 def __iter__(self): return self def next(self): self.count += 1 if self.count > 5: raise StopIteration return self.count >>> for x in Foo(): print x 1 2 3 4 5
Trackback URL: http://www.nishiohirokazu.org/mt/mt-tb.cgi/236