打印缓慢(模拟打字) [英] printing slowly (Simulate typing)
本文介绍了打印缓慢(模拟打字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用 python 制作一个文本游戏.然而,一切顺利,我想制作一个功能,允许我在终端上打印一些东西,但在时尚帽子中看起来像打字.
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.
目前我有:
def print_slow(str):
for letter in str:
print letter,
time.sleep(.1)
print_slow("junk")
输出为:
j u n k
有没有办法去掉字母之间的空格?
Is there a way to get rid of the spaces between the letters?
推荐答案
在 Python 2.x 中,您可以使用 sys.stdout.write
而不是 print
:
In Python 2.x you can use sys.stdout.write
instead of print
:
for letter in str:
sys.stdout.write(letter)
time.sleep(.1)
在 Python 3.x 中,您可以将可选参数 end
设置为空字符串:
In Python 3.x you can set the optional argument end
to the empty string:
print(letter, end='')
这篇关于打印缓慢(模拟打字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文