【发布时间】:2014-09-20 03:38:18
【问题描述】:
好的,我制作了一个慢速打印脚本,我很无聊,所以我想尝试让它看起来很酷。 现在,当我这样做时,它会以一种速度打印所有延迟的打印块。我想做的是让一些线路以不同的速度运行。例如“正在加载:||||||||||”写完需要 5 秒,而“祝你有美好的一天”需要 0.05 秒。
这是我的代码。 # -- 编码:utf-8 -- 进口时间 导入系统
def delay_print(s):
for c in s:
sys.stdout.write( '%s' % c )
sys.stdout.flush()
time.sleep(0.01)
delay_print("Hello!")
delay_print("Please wait while this loads :) ")
delay_print(Loading: ||||||||||") #The line that I want to make slower than the rest
delay_print("Thanks!") #return to regular speed.
【问题讨论】:
-
'%s' % c对字符串没有任何作用,应该只是c。
标签: python performance printing