Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 56939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:36:47+00:00 2026-05-10T17:36:47+00:00

Python, through it’s readline bindings allows for great command-line autocompletion (as described in here

  • 0

Python, through it’s readline bindings allows for great command-line autocompletion (as described in here).

But, the completion only seems to work at the beginning of strings. If you want to match the middle or end of a string readline doesn’t work.

I would like to autocomplete strings, in a command-line python program by matching what I type with any of the strings in a list of available strings.

  • A good example of the type of autocompletion I would like to have is the type that happens in GMail when you type in the To field. If you type one of your contacts’ last name, it will come up just as well as if you typed her first name.
  • Some use of the up and down arrows or some other method to select from the matched strings may be needed (and not needed in the case of readline) and that is fine in my case.
  • My particular use case is a command-line program that sends emails.
  • Specific code examples would be very helpful.

Using terminal emulators like curses would be fine. It only has to run on linux, not Mac or Windows.

Here is an example: Say I have the following three strings in a list

['Paul Eden <paul@domain.com>',  'Eden Jones <ejones@domain.com>',  'Somebody Else <somebody@domain.com>'] 

I would like some code that will autocomplete the first two items in the list after I type ‘Eden’ and then allow me to pick one of them (all through the command-line using the keyboard).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:36:48+00:00Added an answer on May 10, 2026 at 5:36 pm

    I’m not sure I understand the problem. You could use readline.clear_history and readline.add_history to set up the completable strings you want, then control-r to search backword in the history (just as if you were at a shell prompt). For example:

    #!/usr/bin/env python  import readline  readline.clear_history() readline.add_history('foo') readline.add_history('bar')  while 1:     print raw_input('> ') 

    Alternatively, you could write your own completer version and bind the appropriate key to it. This version uses caching in case your match list is huge:

    #!/usr/bin/env python  import readline  values = ['Paul Eden <paul@domain.com>',            'Eden Jones <ejones@domain.com>',            'Somebody Else <somebody@domain.com>'] completions = {}  def completer(text, state):     try:         matches = completions[text]     except KeyError:         matches = [value for value in values                    if text.upper() in value.upper()]         completions[text] = matches     try:         return matches[state]     except IndexError:         return None  readline.set_completer(completer) readline.parse_and_bind('tab: menu-complete')  while 1:     a = raw_input('> ')     print 'said:', a 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 218k
  • Answers 218k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Tools like Lex and Yacc are suitable for your purposes.… May 12, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Boost.Program_options library. Is this you are looking for? The program_options… May 12, 2026 at 11:33 pm
  • Editorial Team
    Editorial Team added an answer Could not parse configuration: jndi:/localhost/MailServerV2/WEB-INF/classes/hibernate.cfg.xml Sounds like it can't find… May 12, 2026 at 11:33 pm

Related Questions

Python, through it's readline bindings allows for great command-line autocompletion (as described in here
I have a simple Python web crawler. It uses SQLite to store its output
I'm making a program that retrieves decently large amounts of data through a python
If I have Python code class A(): pass class B(): pass class C(A, B):
I'm cleaning some of the Python code I wrote when I was...not as knowledgeable.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.