<meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="border-collapse: collapse; color: rgb(51, 51, 51); font-family: arial, sans-serif; font-size: 13px; ">I don't know if this is better (or more "pythonic"), but it works for me on python 2.7.<div>
<br></div><div><div><font face="'courier new', monospace">>>> class MyKlass(object):</font></div><div><font face="'courier new', monospace">...     def __init__(self, tok):</font></div><div><font face="'courier new', monospace">...         self.tok = tok</font></div>
<div><font face="'courier new', monospace">...     def gettoken(self):</font></div><div><font face="'courier new', monospace">...         t, self.tok = self.tok or None, None</font></div><div><font face="'courier new', monospace">...         return t</font></div>
</div></span><br><div class="gmail_quote">On Tue, Jul 19, 2011 at 9:23 AM, Billy Mays <span dir="ltr"><<a href="mailto:81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com">81282ed9a88799d21e77957df2d84bd6514d9af6@myhashismyemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">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:<br>

<br>
def getToken(self):<br>
    if self.tok:<br>
        t = self.tok<br>
        self.tok = None<br>
        return t<br>
    # ...<br>
<br>
<br>
Is there a way to trim the 'if' block to reset self.tok upon return?<br>
<br>
--<br>
Bill<br><font color="#888888">
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br><br><div>Paul Woolcock</div><div><a href="mailto:pwoolcoc@gmail.com">pwoolcoc@gmail.com</a></div><div><br></div><br>