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

标签 python file google-app-engine

我的项目结构是这样的

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/

相关文章:

python - 无法在 Django 中使用 AJAX POST

python - 将 n 个工作日添加到给定日期,忽略 python 中的假期和周末

file - 从包含数千个文件的主文件夹创建 A 到 Z 子文件夹

c - 如何使用 c 在桌面上创建文件

file - 如何从文件更改中热加载结构

python - 使用 Google App Engine (Webapp) 访问 Django 模板中的 session 变量 - Python

python - Google Calendar API (Python) send_event_notifications 不发送电子邮件

python - 将 PostgreSQL 加速到 BigQuery

java - 有没有人让 Recaptcha 在 Google App Engine 上运行(用 Java)?

node.js - 将 Node 应用程序部署到 Google App Engine 标准环境