I am testing a print function, where it looks as if the prompt is typing, defined as type()
I would like to store raw input using the type function:
from time import sleep
import sys
from random import uniform
def type(s):
for c in s:
sys.stdout.write('%s' % c)
sys.stdout.flush()
sleep(uniform(0, 0.3))
name = raw_input(type("What is your name? "))
type("Hello " + name +"\n")
This is the output of the code:
What is your name? None
Input is still allowed from the user, right after 'None', and the output will be correctly printed, without 'None'. Is there a way to circumvent this?
In this prompt I would like to print everything using the type function.
type()toraw_input.typeimplicitely returnsNone, since you did not give it an explicit return value. Perhaps try takingraw_inputinsidetypeand returning the result. As an aside, the nametypealready belongs to the built-in functiontype, and it is bad practice to shadow it. Choose a different name for your function rather thantype.type(). Rename yours totype_()or something else