google appengine不打印数组值

2024-07-01 08:15:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我从googleappengine开始尝试快速学习,但我偶然发现了这个问题,这个问题在我的本地开发中没有出现环境。这里是密码吗

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)

在我的开发环境中,输出是

^{pr2}$

在现场的输出是

45

有谁能告诉我为什么会这样吗?在


Tags: import密码环境israndommaththisseed
2条回答

我自己解决了这个问题

代替print命令,我们必须使用sys.stdout.write('text to print')

您需要import sys才能使上述操作正常工作。在

我无法解释为什么dev服务器和产品之间的行为是不同的,但是在web应用程序中,如果您在没有首先发送HTTP头的情况下简单地向stdout发送print内容,那么您的输出将被破坏。您至少应该在任何其他输出之前打印“\r\n”,尽管无论如何,不使用某种wsgi框架会导致失败。在

相关问题 更多 >

    热门问题