readline module and white-space
MackS
mackstevenson at hotmail.com
Thu May 19 19:01:18 EDT 2005
Dear all,
I'm trying to use Python's readline module but I'm having some trouble.
In particular, autocompletion seems to "get stuck" on white spaces.
Please take a look at this code snippet:
import readline
def completer(text, state):
text = text
list = ['a dog', 'artsy']
if len(text) == 0: expressions = list
else: expressions = [expression for expression in list if
expression.startswith(text)
try:
return expressions[state]
except IndexError:
return None
return
# main code:
readline.parse_and_bind("tab: complete")
readline.set_completer(completer)
string = raw_input("type something: ")
print "typed: " + string
If I type "a" at the prompt and then press tab, both options are
displayed. However, if I then type "[space]d" and then once again ask
for auto-completion (I would expect getting "a dog" filled in for me)
nothing happens.
What am I doing wrong? Can I expect auto-completion to correctly handle
this case?
Thanks in advance for any help,
Mack
More information about the Python-list
mailing list