azalea says

我的第一个Google App Engine程序

http://mooo.appspot.com/

自娱自乐,完全没用。其实是康爷出的练习题的解答。顺便推荐下康爷的博客,有很多关于Google App Engine的东东。

以下是源代码:

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

def fibonacci(n):
    if n==0:
        return [0]
    fibls=[0]*(n+1)
    fibls[0]=0
    fibls[1]=1
    for i in range(2,n+1):
        fibls[i]=fibls[i-1]+fibls[i-2]
    return fibls

fibsrc = '''
def fibonacci(n):
    if n==0:
        return [0]
    fibls=[0]*(n+1)
    fibls[0]=0
    fibls[1]=1
    for i in range(2,n+1):
        fibls[i]=fibls[i-1]+fibls[i-2]
    return fibls
'''

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write(
        r'<a href = "fibonacci">Fib</a><br><a href = "source">Src</a>')

class Fib(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('n'.join(map(str,fibonacci(100))))

class Src(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(fibsrc)

ROUTE = [('/', MainPage),
         ('/fibonacci', Fib),
         ('/source', Src)]

application = webapp.WSGIApplication(ROUTE,debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
GAE programming python · Tweet Edit