How to know if a user has pressed the Enter key using Python -


how know if user has pressed enter using python ?

for example :

user = raw_input("type in enter") if user == "enter":     print "you pressed enter" else:     print "you haven't pressed enter" 

as @jonrsharpe said, way exit raw_input function pressing enter. solution check if result contains or not:

text = raw_input("type in enter") if text == "":     print "you pressed enter" else:     print "you typed text before pressing enter" 

the other ways see quit raw_input function throw exception such as:

  • eoferror if type ^d
  • keyboardinterrupt if type ^c
  • ...

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -