import subprocess
import platform
from time import sleep
def clear_screen():
# thanks to: https://stackoverflow.com/a/23075152/2923937
if platform.system() == "Windows":
subprocess.Popen("cls", shell=True).communicate()
else:
print("\033c", end="")
# obviously you can create a function to convert your string into this
# list rather than doing it manually like I did, but that is another question :p.
views = ['#\nh\n#', '##\nhe\n##', '###\nhel\n###', '####\nhell\n####', '#####\nhello\n#####']
for view in views:
clear_screen()
print(view)
sleep(0.5)
>>> import time
>>> s = '''###############
... Let us begin...
... ###############'''
>>> for c in s:
... print(c, end='', flush=True)
... time.sleep(0.1)
嗯,尽管你的问题含糊不清,我还是想回答这个问题。也许这就是您要找的,它一次打印一列(每行一个字符):
如果已经对字符串中的每个字符执行了
print(c, end='')
,只需将flush=True
添加到对print()
的调用中。休眠调用将引入足够的延迟,以便您可以看到一次打印一个字符:相关问题 更多 >
编程相关推荐