所以我有这段代码,非常基本的东西,我正在努力。我偶然发现了这种“慢类型”的东西,我喜欢它,但如果我使用它而不是所有的打印功能,我的大部分输出都写在一行上。sys.stdout.write不再打印在下一行
import sys, time
def print_slow(str):
for letter in str:
sys.stdout.write(letter)
sys.stdout.flush()
time.sleep(0.02)
print_slow('What\'s your name?')
name = raw_input()
print_slow('My name is ' + name)
if name == 'alex' or name == 'Alex':
print_slow('That\'s a good name')
if name == 'Alexandru' or name == 'alexandru':
print_slow('That\'s a very good name')
将'sys.stdout.write('\ n')'添加到函数定义的末尾(在'for'循环结束之后)。 – khelwood
这写在一个新行的每个字母。 –
这工作。我首先将它添加到循环中。 –