title: How to use a callback function in python?
body: <p>I wonder how to correctly use python 2.7 callback functions.</p>
  
  <p>I have some callback functions from Cherrypy auth examples in my code. </p>
  
  <p>(These callbacks return a function that can evaluate to True or False, depending on the logged in user being in a group or not.)</p>
  
  <p>I wonder if a callback is executed or not if I write a piece of code like this:</p>
  
  <p>Given the definition from the library is:</p>
  
  <pre><code>def member_of(groupname):
      def check():
          if groupname == 'admin':
            if cherrypy.request.login == 'joe':
              return True
            if cherrypy.request.login == 'toni':
              return True
            return False
          return False
          # .... (other groups checked in the same way)
      return check # returns a callback function from my understanding?
  </code></pre>
  
  <p>How can I apply and execute the callback in my code?</p>
  
  <p>If I put it like this:</p>
  
  <pre><code> if member_of('admin'):
      do_something()
    else:
      do_something_else()
  </code></pre>
  
  <p>Will this execute the calllback and check for the admin group? Or will it find out if the value of "member_of" is a function definition and a function definition is probably always a "True" value (or maybe a False value) but both are wrong, because it needs to be executed</p>
  
  <p>Can you enlighten me on this? How can I make sure a callback is executed? An how can I pass it around as it is?</p>