I don't know if this is better (or more "pythonic"), but it works for me on python 2.7.
>>> class MyKlass(object): ... def __init__(self, tok): ... self.tok = tok ... def gettoken(self): ... t, self.tok = self.tok or None, None ... return t On Tue, Jul 19, 2011 at 9:23 AM, Billy Mays < 81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com> wrote: > I have a method getToken() which checks to see if a value is set, and if > so, return it. However, it doesn't feel pythonic to me: > > def getToken(self): > if self.tok: > t = self.tok > self.tok = None > return t > # ... > > > Is there a way to trim the 'if' block to reset self.tok upon return? > > -- > Bill > -- > http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list> > -- Paul Woolcock pwool...@gmail.com
-- http://mail.python.org/mailman/listinfo/python-list