« VMWareと間欠的なディスクアクセスの関係 |Main| 日記 »

« Subversionへの新規importをちょっと楽にするスクリプト | Python | 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)

Trackback URL: http://www.nishiohirokazu.org/mt/mt-tb.cgi/236

ご意見・ご感想をお送りください(フィードバック)

(フィードバックはメールで送信され、基本的に表示されませんが、内容によっては公開させていただくこともございます。ご了承ください。Your comment doesn't appear the page immediately. If the comment has value to other people, it will be put on the page or subsequent entries. Thank you.)

上の情報は、いずれも未記入でかまいません。 All of above questions are optional.