Return and set

Billy Mays 81282ed9a88799d21e77957df2d84bd6514d9af6 at
Tue Jul 19 15:23:52 CEST 2011

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?


More information about the Python-list mailing list