项目开发中有时候等待某个函数返回结果或某些网络请求时,时间比较长,为了让客户感知程序此时还是在正常运行中的,友好的显示,也就是符合UCD,在等待当作我们应该打印点什么,哪怕是一个“.”。python print函数可以简单的达到我们的要求。
>>> help(print)
Help on built-in function print in module builtins:
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
Prints the values to a stream, or to sys.stdout by default. 将值打印到流或sys。默认stdout。
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout. 文件对象(流);默认值为当前sys.stdout。
sep: string inserted between values, default a space. 插入值之间的字符串,默认为空格。
end: string appended after the last value, default a newline. 在最后一个值后面追加的字符串,默认为换行。
flush: whether to forcibly flush the stream. 是否强制刷新。
>>>
那就打印一个“.”吧:
>>> def waiting(say_somthing):
s = '{}'.format(say_somthing)
print(s, end='')
for i in range(100):
print('.', end='')
time.sleep(1)
>>> waiting('testing')
testing....................................................................................................