我的项目结构是这样的
flask-appengine-template/
docs/
licenses/
src/
application/
static/
templates/
models.py
settings.py
urls.py
views.py
english.txt
libs/
bs4/
app.yaml
src.py
在我的 views.py
中,我有一个函数可以读取文件 english.txt
for words in open('english.txt', 'r').readlines():
stopwords.append(words.strip())
当我在 local environment
上运行它时,我在日志中看到错误
(<type 'exceptions.IOError'>, IOError(13, 'file not accessible'), <traceback object at 0x10c457560>)
如何在 Google App Engine 中读取此文件?
最佳答案
如果 english.txt 只是一个单词列表,我建议将单词列表转换为 python 列表,这样你就可以直接导入它。
如果 english.txt 包含更复杂的数据,请将其移动到 bigtable 或您的应用可用的其他数据库。
与标准 VPS 相比,AppEngine 是一个非常糟糕的环境,我倾向于避免在底层操作系统上运行的函数,例如 open()
。
关于python - 谷歌应用引擎 : How to read text file using python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14670388/