用Python使用Google應用服務引擎(GAE)隨手記錄

資料來源:http://code.google.com/intl/zh-TW/appengine/docs/python/runtime.html

==========

from google.appengine.runtime import DeadlineExceededError

class MainPage(webapp.RequestHandler):
def get(self):
try:
# Do stuff…

except DeadlineExceededError:
self.response.clear()
self.response.set_status(500)
self.response.out.write(“This operation could not be completed in time…”)

如果處理常式無法在第二個期限內傳回回應或引發例外狀況,處理常式將終止並傳回預設的錯誤回應。

/////

下列範例示範快取匯入模組的方式。因為單一網頁伺服器只會匯入一次 mymodule,全域 mymodule.counter 只會在伺服器第一次服務要求時初始化為 0。後續的要求會使用之前要求的值。 Continue reading “用Python使用Google應用服務引擎(GAE)隨手記錄”

Python 語法隨手記錄 – 3

書名、原作者、原譯者資訊:

Python 教學文件

作者:
Guido van Rossum
Fred L. Drake, Jr., editor
譯者:
周譯樂


/////程式錯誤與例外(Exceptions)情形

至此為止,我們都只有稍稍的提到錯誤訊息。但是如果你有試著執行上面的範例的話,你可能注意到,基本上錯誤的情況可以分成兩類:語法錯誤 ( syntax errors ) 以及例外情況 ( exceptions )。

/////語法錯誤 Continue reading “Python 語法隨手記錄 – 3”