1) option 1
2) option 2
3) option 3
and then to input some data to the program.
I'm using the raw_input method and it works fine, but I noted that I
can't use backspace and when I accidentally press shift space (because
I need to input uppercase letters separated by a space) it writes some
strange characters.
So, is there another way to get keyboard input?
Thanks,
Carlo
> I need to get keyboard input in a python program. I need it to let the
> user choose some options, for example:
>
> 1) option 1
> 2) option 2
> 3) option 3
>
> and then to input some data to the program.
>
> I'm using the raw_input method and it works fine, but I noted that I
> can't use backspace and when I accidentally press shift space (because
> I need to input uppercase letters separated by a space) it writes some
> strange characters.
That's strange. If you're using Linux, make sure you have the readline
package installed.
> So, is there another way to get keyboard input?
If readline capabilities are not enough, you could try Urwid, a library
for writing console programs: http://excess.org/urwid/ - but it's a big
move. wxPython would let you write a graphical interface (and it's a
bigger move!)
--
Gabriel Genellina
Maybe curses is overkill, but it will do what you need. Most
interactive console apps use curses. You've run into some of the
problems of simply reading STDIN.
>> I'm using the raw_input method and it works fine, but I noted that I
>> can't use backspace and when I accidentally press shift space (because
>> I need to input uppercase letters separated by a space) it writes some
>> strange characters.
>
> That's strange. If you're using Linux, make sure you have the readline
> package installed.
Yes, I have this same issue too, I've just recently installed Python 2.0
(as well as 1.5, 2.4, 2.5, 2.6, 3.0 and 3.1), and while all the other
versions recognise the readline package, this doesn't:
>>> x = 1
>>> # hit up arrow to get previous line
... ^[[A
I'm pretty sure I built 2.0 the same way I built all the others, anyone
have any hints as to what I missed?
--
Steven
> I'm using the raw_input method and it works fine, but I noted that I can't
> use backspace and when I accidentally press shift space (because I need to
> input uppercase letters separated by a space) it writes some strange
> characters.
>
> So, is there another way to get keyboard input?
sys.stdin.readline()
I'm using Linux. Ubuntu. I checked on synaptic and I have
readline-common. Do you mean something else?
Anyway I tried running the program in the iPython shell and it works
great. I mean, I can do backspace and other stuff.
> If readline capabilities are not enough, you could try Urwid, a library for
> writing console programs: http://excess.org/urwid/ - but it's a big move.
> wxPython would let you write a graphical interface (and it's a bigger move!)
Yes, I know about Urwid and wxPython and they're just too much. I was
thinking about curses too, as suggested by others here, but that's too
much too.
> On Sun, 31 Jan 2010 11:51:46 +0000, "Mr.SpOOn" <mr.sp...@gmail.com>
> declaimed the following in gmane.comp.python.general:
>
>> 2010/1/29 Gabriel Genellina <gags...@yahoo.com.ar>:
>> >
>> > That's strange. If you're using Linux, make sure you have the
>> > readline package installed.
>>
>> I'm using Linux. Ubuntu. I checked on synaptic and I have
>> readline-common. Do you mean something else?
>>
> But was your Python /built/ using readline?
How do you ensure that it is?
--
Steven