[英]Python “print” coming after while loop even though it's physically before?
I'm messing around with some python (in eclipse using dynamic language toolkit) and even though I have the print command a line before my while loop, I have to enter the values and type "done" before it prints everything, then it will print the prompt and the values. 我在弄乱一些python(在使用动态语言工具包的eclipse中),即使我在while循环之前的一行上有print命令,我也必须输入值并键入“ done”,然后才能打印所有内容,然后它将打印提示和值。 I've tried using the raw_input() built in prompt as well to no avail. 我试过使用内置提示中的raw_input()也是无济于事的。 Is this just an issue with the editor or is something wrong with my code? 这仅仅是编辑器的问题,还是我的代码有问题?
class squareNums:
def __init__(self):
self.nums = []
self.getInput()
def getInput(self):
print ('Enter values individually, then type "done" when finished')
while True:
var = raw_input()
if var == 'done':
break
else:
self.nums.append(var)
print self.nums
squareNums() squareNums()
I think that's a "feature" of the environment you're executing it in. When run from the command line, I see just what you'd expect: 我认为这是您要在其中执行环境的“功能”。从命令行运行时,我看到的正是您所期望的:
$ python /tmp/tester.py
Enter values individually, then type "done" when finished
123
123
132
123
done
['123', '123', '132', '123']
If I had to guess, I'd say that your terminal is buffering all output until the program ends, and then flushing it all to the screen at once. 如果我不得不猜测,我会说您的终端正在缓冲所有输出,直到程序结束,然后立即将其全部刷新到屏幕上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.