sys.stdout.write no longer prints on next row

前提是你 提交于 2021-02-05 09:28:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!