Pythonのお勉強 Part3000.12
■ このスレッドは過去ログ倉庫に格納されています
0465デフォルトの名無しさん
2006/09/05(火) 00:32:14raise StopIteration() が return のように振舞ってるんですが、何か変な感じです。
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
... yield 1
... raise StopIteration()
... yield 2
...
>>> [x for x in f()]
[1]
元々
list = [1, 2, 3, 4]
try:
it = iter(list)
while 1:
print [it.next() for n in xrange(it.next())]
except StopIteration:
pass
で、it.next() が StopIteration 例外を出して except で捕獲されると
思ったらされなかったのが発端なんですけど。
■ このスレッドは過去ログ倉庫に格納されています