Форум сайта python.su
Как можно сделать так, чтобы в случае ошибки при вводе текста в input()-е не нужно было вводить все заново?
Т.е. чтобы не было такого:
> asd
Ошибка ввода. Введите цифру.
>
А было
> asd
Ошибка ввода. Введите цифру.
> asd
И это asd уже было введено и его можно было бы отредактировать.
Отредактировано chibit (Июль 12, 2012 13:10:39)
Офлайн
Офлайн
s0rgА под Windows есть решение?
http://www.doughellmann.com/PyMOTW/readline/index.html
Офлайн
Офлайн
s0rgIt is not complete. It has been tested for use with windows 2000 and windows xp. К тому же Python 3.2 не поддерживает.
https://github.com/pyreadline/pyreadline
?
Офлайн
chibitТам же исходники, на питоне. Скачали - посмотрели что к чему - переписали как нужно под нужную версию питона.
It is not complete. It has been tested for use with windows 2000 and windows xp. К тому же Python 3.2 не поддерживает.
Офлайн
>>> s = None >>> while s is None: ... s = input('enter: ') ... if not s.isdigit(): ... print('error') ... s = None ... enter: a error enter: b error enter: c error enter: d error enter: 1 >>> s '1' >>>
Офлайн
py.user.nextДык, после вывода “error” тебе нужно вводить все заново. А я хочу сделать так, чтобы по умолчанию было введено предыдущее значение и при желании его можно было изменить.>>> s = None >>> while s is None: ... s = input('enter: ') ... if not s.isdigit(): ... print('error') ... s = None ... enter: a error enter: b error enter: c error enter: d error enter: 1 >>> s '1' >>>
Офлайн
А по стрелке вверх последнее значение вернуть?
Офлайн
chibitа, а то я думал просто нужно вводить, пока не введётся
А я хочу сделать так, чтобы по умолчанию было введено предыдущее значение
[guest@localhost ~]$ rpm -q readline
readline-6.1-2.fc14.i386
[guest@localhost ~]$ rpm -qi readline
Name : readline Relocations: (not relocatable)
Version : 6.1 Vendor: Fedora Project
Release : 2.fc14 Build Date: Чтв 18 Фев 2010 06:22:15
Install Date: Птн 22 Окт 2010 07:59:50 Build Host: x86-07.phx2.fedoraproject.org
Group : System Environment/Libraries Source RPM: readline-6.1-2.fc14.src.rpm
Size : 405301 License: GPLv3+
Signature : RSA/SHA256, Сбт 24 Июл 2010 22:30:53, Key ID 421caddb97a1071f
Packager : Fedora Project
URL : http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
Summary : A library for editing typed command lines
Description :
The Readline library provides a set of functions that allow users to
edit command lines. Both Emacs and vi editing modes are available. The
Readline library includes additional functions for maintaining a list
of previously-entered command lines for recalling or editing those
lines, and for performing csh-like history expansion on previous
commands.
[guest@localhost ~]$
Офлайн