我试图创建一个函数,每次执行某个操作时都返回一个“脉冲”。如果该人希望接收脉冲,则该函数必须作为回调传递。我想打印的脉冲,在同一行新.
性格,所以我这样做:用函数回调在python3中打印同一行
import time
def do_something(do=None):
while True:
time.sleep(1)
if do: do('.')
def prtn(text):
print(text, end=' ')
do_something(prtn)
但代码卡并不会打印出任何东西!
你可能需要刷新输出流才能看到输出。 – thebjorn
@thebjorn是的,它的工作。但为什么? –
@GuerlandoOCs http://stackoverflow.com/a/10019605/1810460 – Hamms