How can I print the status of a Jupyter notebook on the previous line? I think I'm looking for something like clear_output(), but for only a single line.
Sample code:
from IPython.display import clear_output
import time
print('This is important info!')
for i in range(100):
print('Processing BIG data file {}'.format(i))
time.sleep(0.1)
clear_output(wait=True)
if i == 50:
print('Something bad happened on run {}. This needs to be visible at the end!'.format(i))
print('Done.')
Run Code Online (Sandbox Code Playgroud)
When this runs it gives the behavior of over-writing …
这听起来像一个非常简单的问题,所以我很惊讶搜索没有产生任何结果:我想初始化一个常量列表并用另一个源列表扩展它.
这有效:
remoteList = [2, 3, 4]
myList = [0,1]
myList.extend(remoteList)
Run Code Online (Sandbox Code Playgroud)
这意味着它给出了预期的结果:
myList
[0, 1, 2, 3, 4]
Run Code Online (Sandbox Code Playgroud)
但是,在一行中执行列表初始化不起作用,myList未定义:
remoteList = [2, 3, 4]
myList = [0,1].extend(remoteList)
Run Code Online (Sandbox Code Playgroud)
有没有办法初始化列表并用另一个列表(以pythonic方式)在一行中扩展它?为什么我的一行示例不起作用,或者至少产生某种列表?