printing slowly (Simulate typing)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to make a textual game in python. All goes well however, I would like to make a function that will allow me to print something to the terminal, but in a fashion hat looks like typing. Currently I have: def print_slow ( str ): for letter in str : print letter , time . sleep (. 1 ) print_slow ( "junk" ) The output is: j u n k Is there a way to get rid of the spaces between the letters? 回答1: In Python 2.x you can use sys.stdout.write instead of print : for letter in str : sys . stdout . write ( letter ) time . sleep (. 1 )