My script asks for user interaction and asks for his/her name. I am using raw_input to exhibit this functionality. I want to check whether user gave any input or not. I thought to check the entered string with a blank. Currently the code looks like this :
str = raw_input("Enter your name: ")
if("" in str):
print "user din't entered anything"
The above code works partially and if user presses enter without any input, the output user din't entered anything is printed.
The issue is that the above code also works when user enters something like foo bar [Notice the space between foo and bar. Yes I know why this is happening.
Another alternative is to check the length of string entered. If user does not enter anything then length would be zero. But same issue arises here. What if user enters more than one blank ! The length logic will fail.
What shall I do to check whether user inputted any string or left it blank ?
Is there anything for string in python where I can do if(str == "")
Any help appreciated.
if not str: print 'no input''' in xis true for any stringx, not just for strings with spaces in them.