优化输出显示效果
换行不会导致单词分两行显示,并增加类似打字输出的效果;
import sys
import time
defpprint(txt,width=80):
begin=0
end=0
whileTrue:
if begin + width >= len(txt):
for i in txt[begin:]:
sys.stdout.write(i)
sys.stdout.flush()
time.sleep(0.05)
sys.stdout.write('\n')
break
end = txt.rfind(' ', begin, begin + width)
for i in txt[begin:end]:
sys.stdout.write(i)
sys.stdout.flush()
time.sleep(0.05)
sys.stdout.write('\n')
begin = end +1
tt ="The crazy foxjumped over the lazy dog. "*3
print'*'*32
pprint(tt,32)