How does this If conditional work in Python?

Posted by Sergio Boombastic on Stack Overflow See other posts from Stack Overflow or by Sergio Boombastic
Published on 2011-01-15T03:40:40Z Indexed on 2011/01/15 3:53 UTC
Read the original article Hit count: 260

Filed under:
|
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()

        if user:
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('Hello, ' + user.nickname())
        else:
            self.redirect(users.create_login_url(self.request.uri))

application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

I don't understand how this line works:

    if user:
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, ' + user.nickname())
    else:
        self.redirect(users.create_login_url(self.request.uri))

I'm guessing the users.get_current_user() return a boolean? Then, if that is the case how can it get a .nickname() method?

Thanks for the guidance.

© Stack Overflow or respective owner

Related posts about python

Related posts about conditional