Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!feeder.news-service.com!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:verizon.net': 0.07; 'terry': 0.07; 'none:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'wrote:': 0.15; 'artificially': 0.16; 'reedy': 0.16; 'subject:set': 0.16; 'version)': 0.16; 'pm,': 0.16; 'def': 0.16; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'null': 0.23; 'code': 0.24; 'changed': 0.25; '(and': 0.27; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; '(as': 0.34; 'none': 0.35; 'try:': 0.35; 'received:org': 0.38; 'subject:: ': 0.38; 'run': 0.39; 'should': 0.39; 'header:Mime-Version:1': 0.39; 'except': 0.39; 'to:addr:python.org': 0.39; '1:00': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Return and set Date: Tue, 19 Jul 2011 15:18:34 -0400 References: <94577ba1-63ef-4a1b-a150-b004a20755c1@glegroupsg2000goo.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 In-Reply-To: <94577ba1-63ef-4a1b-a150-b004a20755c1@glegroupsg2000goo.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311103132 news.xs4all.nl 23844 [2001:888:2000:d::a6]:34566 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9917 On 7/19/2011 1:00 PM, Micah wrote: > That sounds artificially backwards; why not let getToken() reuse peekToken()? > > def peek(self): > if self.tok is None: > try: > self.tok = self.gen.next() If this is changed (as intended for the iteration protocol) to self.tok = next(self.gen) then this code (and OP's version) should run as is on both Py2.6/7 and Py3. > except StopIteration: > self.tok = NULL > return self.tok > > def pop(self): > token = self.peek() > self.tok = None > return token -- Terry Jan Reedy