ActiveState Community

problem with raw_input() command

Posted by nuvolare on 2009-06-02 13:59

Hello, I'm writing becauase I use Komodo, but now I want to usa the command raw_input(), with this two easy code:

Prompt = "What's your name? "
prova = input(Prompt)

Inserimento = raw_input()
print Inserimento

When I use this I want that the code aske me, "What's you name?"
But It not asking me this and when I run one of those code, they are not asking me but waiting with out ask.
If I write something like "Mark" komodos white :
Mark
What's your name?Mark

Where are the wrong?
Hope you can help me, thank you

toddw | Tue, 2009-06-02 14:05

You'll need to disable the Python output buffering (-u option given to the Python interpreter). See this similar post:
http://community.activestate.com/forum/rawinput-does-not-show

Cheers,
Todd

nuvolare | Wed, 2009-06-03 05:36

Yes, I have read the post, but I understand what I have to do in order to visualize the question before to put the answer
Because now komodo don't aske me anything.
You told me to disable the output buffering, but is this an option?

If I write as there are in the other post, this:

python -u -c "a = raw_input('hello: '); print a"

Komodo says:

File "/Users/nuvolare/Python/ProvaPrompt.py", line 1
python -u -c "a = raw_input('hello: '); print a"
^
SyntaxError: invalid syntax

Thank you

My Version :
Komodo Edit, version 5.0.3, build 2767, platform macosx-x86.
Built on Fri Dec 19 00:21:57 2008.

toddw | Wed, 2009-06-03 11:20

The "-u" unbuffered option is to be passed to the Python interpreter (it is *not* part of the Python file/script).

For example, if your file is /Users/nuvolare/Python/ProvaPrompt.py, then you'd use the following run command (either from Komodo's Tools->Run Command menu, or from a separate terminal console):

python -u /Users/nuvolare/Python/ProvaPrompt.py

and your "ProvaPrompt.py" script file would contain:

a = raw_input('hello: ')
print a
a = raw_input('hello: ')
print a

Cheers,
Todd

nuvolare | Wed, 2009-06-03 11:35

Thank you so much Sir now I have understood.
Because in Komodo's Tools->Run Command menu I've this %(python) "%F" so It work every time i use komodo, but this not work with raw_input
Thank you

toddw | Wed, 2009-06-03 12:27

Yes, so the Komodo "Tools->Run Command" you'd need to use is:
%(python) -u "%F"

Cheers,
Todd