gpt4 book ai didi

python - 谷歌应用引擎 : How to read text file using python?

转载 作者:行者123 更新时间:2023-11-28 20:08:11 25 4
gpt4 key购买 nike

我的项目结构是这样的

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com