You are here: Home / Blogs / How To Enable Auto-Completion in Python Shell

How To Enable Auto-Completion in Python Shell

Learn how to use TAB to auto-complete expressions in plain vannila Python shell.

If you need to have auto completion in Python shell (almost the same way as iPython), it's very easy.

  1. Create a file named .pyreadline with the following content and put it in your home directory.
    #!python
    
    import rlcompleter, readline
    readline.parse_and_bind('tab: complete')
    
  2. Export the file as PYTHONSTARTUP variable; for example append it to .bashrc.
    echo "export PYTHONSTARTUP=~/.pyreadline" >> ~/.bashrc

That's it!

Filed under: ,
Add comment

You can add a comment by filling out the form below. Plain text formatting.

Question: What is 9 + 8 - 2 ?
Your answer: