Appengine won't display Python function
I have a really simple program that checks the date and returns if the combined month+day+year is a so called happy number (a number whos sum of the square of its digits equal one) or not.
The program works fine when I run it locally through python but when I try to run it through the appengine, either locally or online, nothing is displ开发者_运维技巧ayed but a single TEST print line. I can't figure out why the appengine will not display the function.Any help or suggestions would be really appreciated as I'm stuck.
The appengine logs show a GET request:" INFO 2011-04-14 18:19:14,981 dev_appserver.py:3317] "GET / HTTP/1.1" 200 -"
but nothing afterwards.
import sys
import datetime
def main():
date = datetime.date.today()
datearray=[0,0,0]
datearray[0]=str(date.month)
datearray[1]=str(date.day)
datearray[2]=str(date.year)
joined = ''.join(datearray)
print "Date:",int(joined)
print happynums(int(joined))
def happynums(num):
total = int(num)
varnum = 0
bin=0
x=0
past=set()
while total!=1:
if total in past:
return "Sad day :("
past.add(total)
list = map(int,str(total))
total=0
for i in list:
total = total + i**2
if total==1:
return "Happy day :)"
if __name__ == '__main__':
main()
print "TEST"
You can't simply print
to stdout
in a CGI script; you must first send headers followed by a blank line. Your output is being interpreted by your browser as HTTP headers and isn't printing.
You almost certainly want to be using some kind of WSGI framework to handle this for you.
精彩评论