[Tutor] commandline unable to read numbers? (Steven D'Aprano)

Robert Sjoblom robert.sjoblom at gmail.com
Sun Aug 7 16:35:34 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?
Yes, and it goes back to "We need to know who you are, so please
choose either:" The setup.py in question is the distutils.core one
(from distutils.core import setup).

>> 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.
I only copied the relevant part, but here's the entire code if necessary:
http://pastebin.com/PkB6P5fk

>> 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.
I run it like this:
C:\Python32\python.exe setup.py register
(or in the case of menu.py: C:\Python32\python.exe menu.py) -- which,
when started, prints:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\>C:\Python32\python.exe
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>>


>
> 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.
I thought so too at first, but that's not the issue:
C:\Python32\python.exe menu.py

    Notebook Menu

    1. Show All Notes
    2. Search Notes
    3. Add Note
    4. Modify Note
    5. Quit

Enter an option: 1
 <class 'str'>
 is not a valid choice.

-- 
best regards,
Robert S.


More information about the Tutor mailing list