简体   繁体   English

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

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

I'm having an issue on Google App Engine that is pretty weird. 我在Google App Engine上遇到了一个很奇怪的问题。 I have small text file, its 311kbs. 我有一个小的文本文件,它的311kbs。 The text inside needs parsed. 里面的文本需要解析。 My code works fine running local, but when I push it out to GAE, it fails. 我的代码在本地运行良好,但是当我将其发布到GAE时,它失败了。 I've shortened it to the below simple example, to show what breaks. 我将其简化为以下简单示例,以显示中断之处。 The code below fails at writing out what should be in splitlist[0][0], interestingly, if try splitlist[0] it prints out the entire text file. 下面的代码无法写出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)

This kind of pattern is created by the splitlist.append(text.split()) command [["item1", "item2", "item3",]] when I run it local, and I can access the item like this splitlist[0][0] gives me "item1". 这种模式是在本地运行时通过splitlist.append(text.split())命令[[“ item1”,“ item2”,“ item3”,]]创建的,并且可以访问类似于splitlist的项目[0] [0]给我“ item1”。 I've tried this with Python25 and Python27 on app engine, and when deployed it fails as described above. 我已经在应用程序引擎上使用Python25和Python27进行了尝试,并且在部署时如上所述失败。 Any ideas? 有任何想法吗?

Is it possible that something happened to your text file when uploading? 上传时,您的文本文件是否可能发生了某些情况?

It looks like split is not recognizing the '\\n\\n\\n\\n'. 看来split无法识别'\\ n \\ n \\ n \\ n'。

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

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