I\'d like to use a main() function in my GAE code
(note: the code below is just a minimal demonstration for a much larger program, hence the need for a
Seems that the solution was quite simple (it kept eluding me because it hid in plain sight): __name__ is main and not __main__!
In short, the following code utilises a main() as expected:
# with main()
import webapp2
class GetHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('in GET')
class SetHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('in SET')
def main():
global app
app = webapp2.WSGIApplication([
('/get', GetHandler),
('/set', SetHandler),
], debug=True)
# Note that it's 'main' and not '__main__'
if __name__ == 'main':
main()