1

I know I can use this:

import rlcompleter, readline
readline.parse_and_bind('tab: complete')

to enable ipython-style tab completion in my python interpreter.

How can I make this run by default on start, anytime I start python?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246

1 Answers1

3

Put that into a file .pythonrc (You can control the name of that file by the environment variable PYTHONSTARTUP). Read more about here:

PYTHONSTARTUP
If this is the name of a readable file, the Python commands 
in that file are executed before the first prompt is displayed
in interactive mode. The file is executed in the same namespace
where interactive commands are executed so that objects defined
or imported in it can be used without qualification in the interactive
session. You can also change the prompts sys.ps1 and sys.ps2 in this file.

see also:

Community
  • 1
  • 1
akira
  • 6,050
  • 29
  • 37
  • You linked the question about Python 2.7 vs 3.2 - does this mean that you have to do something different for 2 vs 3 in OP's code? – 2rs2ts Jul 12 '13 at 15:46
  • Ah, probably not the case... `readline` is implemented with `libedit` instead on OS X. You have to use `"bind ^I rl_complete"` instead according to [this answer](http://stackoverflow.com/a/7116997/691859). – 2rs2ts Jul 12 '13 at 16:13
  • I appear not to have a .pythonrc file. Is there a recommended, standard place to put one on an ubuntu machine? `Just export PYTHONSTARTUP=$HOME/.pythonrc` like in the other answer you mentioned? – Mittenchops Jul 12 '13 at 17:05