2010年2月6日 星期六

疑難排解:無法正常實作Python自定物件

 

底下程式匯入Model.py

裡面宣告自定物件WooTuUser

在第13行實作該物件卻發現沒有反應

在debug模式下,執行到該行會閃兩次

接著直接跳到_init_.py的return func(*params)

經測試後發現是Python無法正確匯入WooTuUser物件的關係

後來把第4行的”import Model”

改成”from Model import WooTuUser

就可以正確執行了

  1: import wsgiref.handlers
  2: from google.appengine.ext import webapp
  3: from pyamf.remoting.gateway.google import WebAppGateway
  4: import Model
  5: 
  6: class MainPage(webapp.RequestHandler):
  7:     def get(self):
  8:         self.response.headers['Content-Type'] = 'text/plain'
  9:         self.response.out.write('Hello, World!')
 10: 
 11: 
 12: def echo(data):
 13:     u = WooTuUser(id=data.id, password=data.password)
 14:     u.put()
 15:     return data
 16: 
 17: services = { 'myservice.echo': echo, }
 18: 
 19: def main():  
 20:     application_paths = [('/', WebAppGateway(services)), ('/helloworld', MainPage)]
 21:     application = webapp.WSGIApplication(application_paths, debug=True,)
 22:     wsgiref.handlers.CGIHandler().run(application)





 

Related Posts with Thumbnails
by TemplatesForYou-TFY
SoSuechtig