Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Keyboard input

10 views
Skip to first unread message

Mr.SpOOn

unread,
Jan 29, 2010, 11:53:43 AM1/29/10
to Python List
Hi,
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.

So, is there another way to get keyboard input?

Thanks,
Carlo

Gabriel Genellina

unread,
Jan 29, 2010, 4:38:47 PM1/29/10
to pytho...@python.org
En Fri, 29 Jan 2010 13:53:43 -0300, Mr.SpOOn <mr.sp...@gmail.com>
escribi�:

> 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

Message has been deleted

Jonathan Gardner

unread,
Jan 29, 2010, 5:15:30 PM1/29/10
to

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.

Steven D'Aprano

unread,
Jan 29, 2010, 10:03:04 PM1/29/10
to
On Fri, 29 Jan 2010 18:38:47 -0300, Gabriel Genellina wrote:

>> 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

Nobody

unread,
Jan 30, 2010, 11:54:52 AM1/30/10
to
On Fri, 29 Jan 2010 16:53:43 +0000, Mr.SpOOn wrote:

> 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()

Mr.SpOOn

unread,
Jan 31, 2010, 6:51:46 AM1/31/10
to Gabriel Genellina, pytho...@python.org
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?

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.

Message has been deleted

Steven D'Aprano

unread,
Jan 31, 2010, 5:40:55 PM1/31/10
to
On Sun, 31 Jan 2010 14:10:34 -0800, Dennis Lee Bieber wrote:

> 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

Message has been deleted
0 new messages