Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';I’调用方法时,我希望打印时不使用换行符_Python_Methods_Printing_Newline - Fatal编程技术网

Python I';I’调用方法时,我希望打印时不使用换行符

Python I';I’调用方法时,我希望打印时不使用换行符,python,methods,printing,newline,Python,Methods,Printing,Newline,我调用一个简单的小方法,它每秒打印一个初始语句和一个句点。它将每个新点打印在一行上,我希望它们都在一行上,就像这样:“检查……” 当我在print语句后面加逗号时,或者如果我使用sys.stdout.write(),该方法将挂起,直到整个循环完成,然后一次全部打印 这是我的密码。使用Python2.4.3——恐怕别无选择 class WaitTimer(object): def timer(self, time, countDown=0): if countDown =

我调用一个简单的小方法,它每秒打印一个初始语句和一个句点。它将每个新点打印在一行上,我希望它们都在一行上,就像这样:“检查……”

当我在print语句后面加逗号时,或者如果我使用
sys.stdout.write()
,该方法将挂起,直到整个循环完成,然后一次全部打印

这是我的密码。使用Python2.4.3——恐怕别无选择

class WaitTimer(object):

    def timer(self, time, countDown=0):
        if countDown == 0:
            print "\nChecking.",
        if countDown <= time:
            countDown += 1
            print ".",

            self.timer(time, countDown)

wait = WaitTimer()

wait.timer(5)
类等待计时器(对象):
def定时器(自身、时间、倒计时=0):
如果倒计时=0:
打印“\n检查。”,

如果倒计时我认为您可能希望在需要显示数据时调用
sys.stdout.flush()
。我不认为
打印“废话”
会有什么效果

使用
sys.stdout.write()
sys.stdout.flush()
试试看:
print“blah”
包括一个换行符,因此是flush。但是,不要像我写的那样打印“blah”。哦,你是对的-没有注意到逗号。最好写“用逗号”这是罚单。当我尝试使用sys.stdout.write()时,我只在循环外刷新了一次。在每个sys.stdout.write()之后,将刷新放在循环中完成。谢谢Owen和Elazar