[Tutor] commandline unable to read numbers?

Steven D'Aprano steve at pearwood.info
Sun Aug 7 07:00:16 CEST 2011


Robert Sjoblom wrote:
> I have a quite odd problem, and I've come across it before but
> probably ignored it at the time because I had other concerns. I've
> tried googling for the answer but haven't really come closer to
> solving it.
> This is what happens:
> C:\[path]\nester>C:\Python32\python.ex
> e setup.py register
> running register
> running check
> We need to know who you are, so please choose either:
>  1. use your existing login,
>  2. register as a new user,
>  3. have the server generate a new password for you (and email it to you), or
>  4. quit
> Your selection [default 1]:
> 1
> Please choose one of the four options!

Looks like a bug in the setup.py script. You should report it to the 
author of the package.

Have you tried just pressing enter without entering anything?


> No matter what I enter it will loop back. It seems my commandline
> can't read numbers? The other time I noticed it was while working on a
> notebook example:
[...]
> This code works in IDLE, so I know it's nothing in the actual code
> that's a problem, 

Apart from the fact that it is incomplete and won't run as given, it 
seems fine.


> but when I run it in commandline it will just repeat
> "is not a valid choice." Note that it does this no matter what I
> actually enter, it won't actually get any kind of input except the
> enter key. So I suppose it's a problem with input() (I'm using python
> 3.2 btw). Anyone have any insights?

You're not telling us how you're running it from the command line. My 
guess is that when you try, you're ending up with a different version of 
Python, namely Python 2.x, where input() has different semantics.

Try putting

print("choice = ", choice, type(choice))

immediately after the call to input in your code, and seeing what it 
prints. My guess is that it will claim choice is a int instead of a string.


-- 
Steven



More information about the Tutor mailing list