sys.stdin.readline() reads without prompt, returning 'nothing in between'

前端 未结 6 2209
被撕碎了的回忆
被撕碎了的回忆 2021-02-12 15:49

I have a function that executes the following (among other things):

userinput = stdin.readline()
betAmount = int(userinput)

Is supposed to tak

6条回答
  •  时光取名叫无心
    2021-02-12 16:26

    stdin.read(1)
    

    will not return when you press one character - it will wait for '\n'. The problem is that the second character is buffered in standard input, and the moment you call another input - it will return immediately because it gets its input from buffer.

提交回复
热议问题