0

I began messing around in python trying to create a frozen exe, i finally got it to work, then discovered that the input function doesn't seem to work properly when ran through the command prompt as opposed to in idle, or the interactive session. Any ideas why, or how to fix this?

Edit: When i say not properly, I mean it asks for input, but when i enter one, it does nothing. When i enter something in idle it does exactly what it's supposed to. It acts like i did nothing.

I'm using cx_freeze, didn't seem relevant because i tried just running the script in CMD without freezing it and it did the same thing.

while idea != 'new':
    idea = input('...')
    if idea == 'hit':
        del hand2[0:]
        del hand4[0:]
        hand2.append(random.choice(num))
        for i in hand2:
            if i == 10:
                a = random.choice(num2)
                hand.append(10)
                hand3.append(a)
            elif i == 1:
                if sum(hand) + 11 < 21:
                    hand.append(11)
                    hand3.append('Ace')
                else:
                    hand.append(1)
                    hand3.append('Ace')
            else:
                hand3.append(i)
                hand.append(i)

It will not acknowledge that i typed in hit, even though it does in idle and the interactive session.

5
  • Answering this questions as it is would be close to guessing, please expand your question with as much information about you problem as possible, and preferably, al least some relevant code. Otherwise I don't think you'll get any good answers. Thanks! please also, take a look at our FAQ Commented May 5, 2011 at 15:10
  • Also define "frozen exe". Are you using py2exe, PyInstaller, or trying to do it yourself with a core dump? Commented May 5, 2011 at 15:11
  • This seems to be Python 3.x. Correct? Commented May 5, 2011 at 15:26
  • Try printing repr(idea) directly after the input() call. It's possible the newline character is included in cmd, while it's not included in IDLE. Commented May 5, 2011 at 15:42
  • When you added print() functions after input(), what did you see? Commented May 5, 2011 at 15:44

1 Answer 1

1

If you're trying to get a user string input, the function is named raw_input() (at least that's what it's called in Python 2.7). This code works as expected from cmdline using Python 3.2:

idea = ''
while idea != 'new':
    idea = input('...').strip()
    if idea == 'hit':
        print("It's not nice to hit people (or computers).")
    else:
        print('you input [{}]'.format(idea))

Had to add the .strip() onto input call to get it to match the string 'hit' as the input appears to include the carriage return.

Sign up to request clarification or add additional context in comments.

5 Comments

Ah, sorry, made the mistake of assuming 2.x... But are you sure you're running 3.x in both cases (IDLE vs. cmdline)? Run "python -V" from command line and compare to what you see in IDLE when you fire it up.
It is Python 3.2 in the cmd, just checked.
That works perfectly, thank you. If i had the rep I'd upvote this.
That's weird, what OS? It does not include the CR on Ubuntu.
Windows 7, That's what i'm using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.