Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.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 sys.stdout.flush在jupyter笔记本中不工作_Python_Jupyter Notebook_Flush - Fatal编程技术网

Python sys.stdout.flush在jupyter笔记本中不工作

Python sys.stdout.flush在jupyter笔记本中不工作,python,jupyter-notebook,flush,Python,Jupyter Notebook,Flush,因此,我只想重新运行此repo中的代码: 我的重点是印刷品部分: for i_episode in range(1, num_episodes + 1): # Print out which episode we're on, useful for debugging. if i_episode % 1000 == 0: print "\rEpisode {}/{}.".format(i_episode, num_episodes)

因此,我只想重新运行此repo中的代码:

我的重点是印刷品部分:

 for i_episode in range(1, num_episodes + 1):
        # Print out which episode we're on, useful for debugging.
        if i_episode % 1000 == 0:
            print "\rEpisode {}/{}.".format(i_episode, num_episodes)
            sys.stdout.flush()
他正在使用sys.stdout.flush()创建一个简单的“进度”输出。您可以看到他的repo的输出,它只显示最后一集迭代
10000/10000
,因为使用sys.stdout.flush()

但是,当我尝试在Jubyter笔记本中运行时(我使用cmd命令
jupyter笔记本
)运行时,我认为sys.stdout.flush()不起作用,它会显示每个打印的迭代,而不是覆盖前一次迭代:

Episode 1000/10000.
Episode 2000/10000.
Episode 3000/10000.
Episode 4000/10000.
Episode 5000/10000.
Episode 6000/10000.
Episode 7000/10000.
Episode 8000/10000.
Episode 9000/10000.
Episode 10000/10000.

当运行jupyter使其工作时,我是否遗漏了一些东西?

无生气的达菲评论将一切都说得很清楚。覆盖问题不在打印功能中的刷新功能buat上

我发现解决方案只是从以下位置编辑打印格式:

print("\rEpisode {}/{}.".format(i_episode, num_episodes))


覆盖现在起作用了

导致覆盖的是
\r
s,而不是
flush()
——它只是确保内容不会卡在缓冲区中。因为它关注的不是关键组件,所以现在写的有点混乱。哦。。我不知道那里有
\r
符号,谢谢:)现在很清楚,如果您的stdout是未缓冲的(而不是行缓冲的,这通常是TTY的默认值),这将在根本没有
flush()
的情况下工作。将其描述为“flush”是有效的还是无效的没有多大意义。没错,我认为flush是负责通过猜测覆盖的,我不知道那里有
\r
符号,谢谢,我将编辑itor
print”\rEpisode{}/{}。format(I_插曲,num_插曲),如果是python 2.x的话,
print("\rEpisode {}/{}.".format(i_episode, num_episodes), end="")