问题
So I have this piece of code, very basic stuff that I'm working on. I stumbled upon this "slow type" thing, that I like but if I use it instead of all print functions, most of my output is written on one row.
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')
回答1:
You can print a newline character (\n
) at the end of each line where you so desire, or add it to the print_slow
function.
来源:https://stackoverflow.com/questions/45149870/sys-stdout-write-no-longer-prints-on-next-row