raw_input in python without pressing enter

后端 未结 8 1501
情歌与酒
情歌与酒 2020-11-22 15:41

I\'m using raw_input in Python to interact with user in shell.

c = raw_input(\'Press s or n to continue:\')
if c.upper() == \'S\':
    print \'Y         


        
8条回答
  •  遇见更好的自我
    2020-11-22 16:06

    Python does not provide a multiplatform solution out of the box.
    If you are on Windows you could try msvcrt with:

    import msvcrt
    print 'Press s or n to continue:\n'
    input_char = msvcrt.getch()
    if input_char.upper() == 'S': 
       print 'YES'
    

提交回复
热议问题