Null number input

Lao Coon laocoon at
Sun Jan 26 22:31:20 CET 2003

Tyson Tate <nilobject at> wrote in
news:mailman.1043614666.18370.python-list at 

> When I use raw_input, I'm able to not enter anything and just hit 
> return, yet with input, I get "unexpected EOF while parsing" if I
> don't enter anything. The code I am using is as follows (my remarks =
> #): 
>      userInfo["firstName"] = raw_input("First Name: ")        # Works
>      fine userInfo["lastName"] = raw_input("Last Name: ")       # same
>      here userInfo["age"] = input("Age: ")       # entering nothing
>      gives me the 
> error
>      userInfo["SSN"] = input("SSN: ")
> Would I have to do something like int(raw_input("Age: ")) or is there
> a better way?

Have you actually tried that? int(raw_input("Age: ")) with no input will 
result in int('') which will raise ValueError. 
Catching the exception is the best thing to do.
After all if the user doesn't enter an age you might want to note it..

    	userInfo["age"] = input("Age: ")
except SyntaxError:
    	userInfo["age"] = 0 # or whatever you wanna do here..


More information about the Python-list mailing list