【发布时间】:2019-10-14 18:24:36
【问题描述】:
我有一段代码如下所示:
for l in blah:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.025)
这会在打印语句中打印的每个字符之间增加一点延迟,该语句分配给变量blah。但是,如果 print 语句中存在变量,例如:
blah = "\n", player_name, ", you must save this land from the virus that has blighted us.\n"
那么打印语句将不会像我想要的那样打印,而是像正常的打印语句那样打印。
我希望打印语句会像被逐行快速键入一样打印出来,但实际上打印语句是一次性打印出来的。
【问题讨论】:
-
"\n", player_name, ", you must save this land from the virus that has blighted us.\n"是一个由三个元素组成的 元组,其中两个是字符串。所以,blah[2]是字符串", you must save this land from the virus that has blighted us.\n"。 -
blah如您所见是元组而不是字符串。您可以使用 stackoverflow.com/questions/19641579/… 中提到的内容将其转换为字符串
标签: python