Return and set
Terry Reedy
tjreedy at udel.edu
Tue Jul 19 15:18:34 EDT 2011
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
More information about the Python-list
mailing list