[Tutor] commandline unable to read numbers?

Robert Sjoblom robert.sjoblom at gmail.com
Sun Aug 7 05:42:07 CEST 2011


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!
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]:

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:

class Menu:
    """Display a menu and respond to choices when run."""
    def __init__(self):
        self.notebook = Notebook()
        self.choices = {
            "1": self.show_notes,
            "2": self.search_notes,
            "3": self.add_note,
            "4": self.modify_note,
            "5": self.quit
            }

    def display_menu(self):
        print("""
    Notebook Menu

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

    def run(self):
        """Display the menu and respond to choices."""
        while True:
            self.display_menu()
            choice = input("Enter an option: ")
            action = self.choices.get(choice)
            if action:
                action()
            else:
                print("{0} is not a valid choice.".format(choice))

This code works in IDLE, so I know it's nothing in the actual code
that's a problem, 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?
-- 
best regards,
Robert S.


More information about the Tutor mailing list