0

By printing out of raw_input() appears at the end a "none".

I defined above a function to look nice when printing the question.

Here's my code:

def delay_print_input(string):
  for c in string:
    sys.stdout.write(c)
    sys.stdout.flush()
    time.sleep(0.15)

ans=raw_input(delay_print_input("What do you want?\n>> "))

The output looks like:

What do you want?
>> None

My question is, how can I remove this none?

Andy K
  • 4,944
  • 10
  • 53
  • 82
Lamera
  • 13
  • 1

2 Answers2

3

Your function returns None, which raw_input then prints. What you want is this:

def delay_print_input(string):
  for c in string:
    sys.stdout.write(c)
    sys.stdout.flush()
    time.sleep(0.15)

delay_print_input("What do you want?\n>> ")
ans=raw_input()
L3viathan
  • 26,748
  • 2
  • 58
  • 81
1

Your function is returning None and sending it to the input function. You can just return a blank string in your function

def delay_print_input(string):
    for c in string:
        sys.stdout.write(c)
        sys.stdout.flush()
        time.sleep(0.15)
    return ""
Whud
  • 714
  • 1
  • 6
  • 19