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


Groups > comp.lang.python > #9917

Re: Return and set

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Return and set
Date 2011-07-19 15:18 -0400
References <j0427i$rdb$1@speranza.aioe.org> <94577ba1-63ef-4a1b-a150-b004a20755c1@glegroupsg2000goo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1274.1311103132.1164.python-list@python.org> (permalink)

Show all headers | 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