2017-01-16 28 views
2

是否可以讓ipython執行以下操作?在單元運行時更改ipython中的輸出

#A cell... 
output("a") # the cell output shows "a" 
change_output("b") # the cell output now shows "b". "a" has been deleted 

我想要這種行爲,以便單元格輸出可以顯示當前運行狀態,沒有大量的輸出行。

回答

1

是的,是這樣的:

import sys 
from IPython.core.display import clear_output 
def change_output(x): 
    clear_output() 
    sys.stdout.write(x) 
    sys.stdout.flush() 

change_output("a") 
change_output("b")