Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9917

Re: Return and set

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 <python-python-list@m.gmane.org>
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 <tjreedy@udel.edu>
Subject Re: Return and set
Date Tue, 19 Jul 2011 15:18:34 -0400
References <j0427i$rdb$1@speranza.aioe.org> <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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1274.1311103132.1164.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: Return and set Micah <larson.micah@gmail.com> - 2011-07-19 10:00 -0700
  Re: Return and set Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com> - 2011-07-19 13:12 -0400
  Re: Return and set Terry Reedy <tjreedy@udel.edu> - 2011-07-19 15:18 -0400

csiph-web