2011-03-08 61 views
0

我開始與谷歌應用程序引擎,並試圖一些快速learning.I過這個問題,它不會對我的地方發展environment.Here發生是偶然的代碼谷歌AppEngine上不打印數組值

import random, math 
random.seed() 

quotesArray=[] 
quotesArray.append("This is a Test1") 
quotesArray.append("This is a Test2") 
quotesArray.append("This is a Test3") 
quotesArray.append("This is a Test4") 
quotesArray.append("This is a Test5") 


x = int(math.floor(random.random()*343)+1) 
print quotesArray[0]+" "+str(x) 

在我的開發環境的輸出

This is a Test1 45 

在現場直播的輸出是

45 

任何人都可以請提供一些想法,爲什麼會這樣?

+1

當您使用logging.debug()而不是打印時,這也會發生嗎? – 2011-03-08 22:16:06

回答

0

我通過解決這個問題我自己

相反print命令,我們必須使用sys.stdout.write('text to print')

您需要import sys爲上述工作得到了。

+0

它有可能是與標準輸出是什麼...可能是應用程序引擎中的一個錯誤,它無法識別'print'的輸出需要去哪裏... – Rupin 2011-03-10 06:35:02

0

我無法解釋爲什麼開發服務器和生產之間的行爲不同,但在Web應用程序中,如果您只是在沒有首先發送HTTP標頭的情況下將stdout標記爲print,則應該期望您的輸出將會得到錯位。你至少應該在任何其他輸出之前打印「\ r \ n」,儘管不使用某種類型的wsgi框架無論如何都是挫敗感。

+0

我已經把下面的代碼,仍然沒有outputs.its一個空白的屏幕上的現場環境,但本地主機打印很好'print'Content-Type:text/plain'loveQuotes = [] loveQuotes.append(「Test1 「) loveQuotes.append(」 Test2的 「) loveQuotes.append(」 Test3的 「) loveQuotes.append(」 TEST4" ) 打印loveQuotes [1]' – Rupin 2011-03-10 05:16:35