Найти - Пользователи
Полная версия: Вывести в консоль текст во время работы input()-а
Начало » Python для новичков » Вывести в консоль текст во время работы input()-а
1
chibit
Как можно сделать так, чтобы в случае ошибки при вводе текста в input()-е не нужно было вводить все заново?
Т.е. чтобы не было такого:
> asd
Ошибка ввода. Введите цифру.
>

А было
> asd
Ошибка ввода. Введите цифру.
> asd
И это asd уже было введено и его можно было бы отредактировать.
chibit
s0rg
http://www.doughellmann.com/PyMOTW/readline/index.html
А под Windows есть решение?
s0rg
https://github.com/pyreadline/pyreadline
?
chibit
s0rg
https://github.com/pyreadline/pyreadline
?
It is not complete. It has been tested for use with windows 2000 and windows xp. К тому же Python 3.2 не поддерживает.
s0rg
chibit
It is not complete. It has been tested for use with windows 2000 and windows xp. К тому же Python 3.2 не поддерживает.
Там же исходники, на питоне. Скачали - посмотрели что к чему - переписали как нужно под нужную версию питона.
В чем проблема-то?

Если ‘tested for use with windows 2000 and windows xp’ то значит NT - линейка поддерживается.
Значит и на XP+ должно работать. Или вам под 9x нужно?
py.user.next
>>> 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
py.user.next
>>> 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'
>>> 
Дык, после вывода “error” тебе нужно вводить все заново. А я хочу сделать так, чтобы по умолчанию было введено предыдущее значение и при желании его можно было изменить.
odnochlen
А по стрелке вверх последнее значение вернуть?
py.user.next
chibit
А я хочу сделать так, чтобы по умолчанию было введено предыдущее значение
а, а то я думал просто нужно вводить, пока не введётся
в лине при установленном readline история ввода сохраняется
[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 ~]$
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB