Typing effect in Python
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to make such program which reads characters from a string and prints each character after some delay so its look like typing effect. Now my problem is sleep function is not working properly. It print whole sentence after long delay. import sys from time import sleep words = "This is just a test :P" for char in words: sleep(0.5) sys.stdout.write(char) I use "sys.stdout.write" for removing whitespace between characters. 回答1: you should use sys.stdout.flush() after each iteration The problem is that stdout is flushed with the newline or