GoogleAppEngine:如何使用python读取文本文件?

day*_*mer 2 python google-app-engine file

我的项目结构看起来像

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
Run Code Online (Sandbox Code Playgroud)

在我views.py,我有一个读取文件的功能english.txt

      for words in open('english.txt', 'r').readlines():
            stopwords.append(words.strip())
Run Code Online (Sandbox Code Playgroud)

当我运行它时local environment,我在日志中看到错误

(<type 'exceptions.IOError'>, IOError(13, 'file not accessible'), <traceback object at 0x10c457560>)
Run Code Online (Sandbox Code Playgroud)

如何在Google App Engine中阅读此文件?

Pau*_*ine 6

如果english.txt只是一个单词列表,我建议将单词列表转换为python列表,这样你就可以导入它.

如果english.txt包含更复杂的数据,请将其移至您的应用程序可用的bigtable或其他数据库.

与标准VPS相比,AppEngine是一个非常残缺的环境,我倾向于避免在底层操作系统上运行的功能open().