Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'correct.': 0.07; 'def': 0.12; '(self):': 0.16; 'col': 0.16; 'container,': 0.16; 'doubly': 0.16; 'iteration': 0.16; 'message-id:@earthlink.net': 0.16; 'trying': 0.19; 'header:User-Agent:1': 0.23; "i've": 0.25; 'correct': 0.29; 'raise': 0.29; "doesn't": 0.30; "i'm": 0.30; 'says': 0.33; 'url:python': 0.33; 'received:66': 0.35; 'indexed': 0.36; 'yield': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'url:3': 0.61; 'subject:skip:S 10': 0.84 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=ijqRoXvVzhaSTcPOL7FjIth8EwiLOWn9g2tx8xoKGKExVIGYTSoZu2uo4Lz3gACU; h=Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding:X-ELNK-Trace:X-Originating-IP; Date: Mon, 09 Feb 2015 11:14:55 -0800 From: Charles Hixson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: python-list@python.org Subject: __next__ and StopIteration Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-ELNK-Trace: 8d80e6a64fbe03f9b17f27b91410de884d2b10475b571120318a924da6b73ca37262f4754cc163f2bd40f6fca822b641350badd9bab72f9c350badd9bab72f9c X-Originating-IP: 66.245.47.138 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423509383 news.xs4all.nl 2966 [2001:888:2000:d::a6]:47195 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85394 I'm trying to write a correct iteration over a doubly indexed container, and what I've got so far is: def __next__ (self): for row in range(self._rows): for col in range(self._cols): if self._grid[row][col]: yield self._grid[row][col] #end if #end for col #end for row raise StopIteration What bothers me is that it doesn't look like it would continue to raise StopIteration if it were called again, which is what https://docs.python.org/3/library/stdtypes.html#iterator.__next__ says is correct. How should this be fixed?