Python 如何让它看起来像电脑在打字?

Python 如何让它看起来像电脑在打字?,python,python-3.x,Python,Python 3.x,我想让它看起来像是计算机正在试图输入回用户。我试过一些代码,但当我运行它时,它只会一次打印所有内容,即使我一次打印一个 A = "Random sentence" for x in A: time.sleep(random.randint(1,4)) print(x, end='') 您需要使用stdout.flush()。这将迫使它在每次打印后显示 import sys A = "Random sentence" for x in A: time.sleep(ran

我想让它看起来像是计算机正在试图输入回用户。我试过一些代码,但当我运行它时,它只会一次打印所有内容,即使我一次打印一个

A = "Random sentence"
for x in A:
    time.sleep(random.randint(1,4))
    print(x, end='')

您需要使用
stdout.flush()
。这将迫使它在每次打印后显示

import sys

A = "Random sentence"
for x in A:
    time.sleep(random.randint(1,4))
    print(x, end='')
    sys.stdout.flush()

pyautogui
模块中使用
pyautogui.typewrite
,您可以让计算机实际键入。。。