繁体   English   中英

Google App Engine,Python列表处理-访问列表索引[0] [0]时出错

[英]Google App Engine, Handling of Python Lists - Error accessing List Index[0][0]

我在Google App Engine上遇到了一个很奇怪的问题。 我有一个小的文本文件,它的311kbs。 里面的文本需要解析。 我的代码在本地运行良好,但是当我将其发布到GAE时,它失败了。 我将其简化为以下简单示例,以显示中断之处。 下面的代码无法写出splitlist [0] [0]中应该包含的内容,有趣的是,如果尝试splitlist [0],它将打印出整个文本文件。

import webapp2
import os, re

#Load the text file...
file = os.path.join(os.getcwd(), 'TextFileEN.txt')
openfile=open(hymnfile)
text=openfile.read()
#List for split text
splitlist=[]

#Split text on the consistent 4 carriage returns.
textsplit=splitlist.append(text.split('\n\n\n\n'))

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(splitlist[0][0])

app = webapp2.WSGIApplication([('/', MainPage)], debug=True)

这种模式是在本地运行时通过splitlist.append(text.split())命令[[“ item1”,“ item2”,“ item3”,]]创建的,并且可以访问类似于splitlist的项目[0] [0]给我“ item1”。 我已经在应用程序引擎上使用Python25和Python27进行了尝试,并且在部署时如上所述失败。 有任何想法吗?

上传时,您的文本文件是否可能发生了某些情况?

看来split无法识别'\\ n \\ n \\ n \\ n'。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM