我正在創建一個用戶可以輸入段落文本的應用程序,並對段落運行拼寫檢查。我通過打開包含我的字典的文件'words.txt'使用python在本地文檔中實現了這一點。我試圖弄清楚如何打開一個實施我的拼寫檢查的單詞列表。創建拼寫檢查,需要訪問App Engine中的words.txt
我的第一次嘗試是將它作爲一個靜態文件放在我的目錄中,然後對文件執行一次提取操作,但我一直收到一個錯誤消息。
這裏是我的文件:
的app.yaml:
application: *******
version: 1
runtime: python
api_version: 1
handlers:
- url: /(.*\.txt)
mime_type: text/plain
static_files: static/\1
upload: static/(.*\.txt)
- url: /.*
script: helloworld.py
摘錄 helloworld.py
import os
from google.appengine.ext.webapp import template
import cgi
import datetime
import urllib
import wsgiref.handlers
from google.appengine.api import urlfetch
from google.appengine.ext import db
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
....
result=urlfetch.fetch(os.path.join(os.path.dirname(__file__),'words.txt'))
words=set(result.splitlines())
有什麼不對?我不斷收到錯誤。
可能重複[用Python讀取App Engine上的文件?](http://stackoverflow.com/questions/2630205/read-a-file-on-app-engine-with-python) – geoffspear 2012-02-10 12:43:06