Alex Toma
Alex Toma

Reputation: 101

sys.stdout.write no longer prints on next row

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')

Upvotes: 1

Views: 10133

Answers (1)

Cary Shindell
Cary Shindell

Reputation: 1386

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.

Upvotes: 3

Related Questions