我在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,并在部署时失败,如上所述。有什么想法吗?
答案 0 :(得分:0)
上传时文本文件可能发生了什么?
看起来拆分无法识别'\ n \ n \ n \ n'。