簡體   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