readline module and white-space

M

MackS

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
 
S

Simon Percivall

Take a look at readline.get_completer_delims() and
readline.set_completer_delims().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top