0

python tab completion Mac OSX 10.7 (Lion)

The above link shows that the following code can be used for autocompletion in python.

import readline
import rlcompleter
if 'libedit' in readline.__doc__:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")

But I don't see where to put it so that it can be loaded at startup. I tried ~/.pythonrc, but it did not work.

Does anybody know what is the current way to load such a configuration automatically for an interactive python session?

user1424739
  • 11,937
  • 17
  • 63
  • 152

2 Answers2

1

You need to set PYTHONSTARTUP environment variable to ~/.pythonrc. Put PYTHONSTARTUP=~/.pythonrc into your .bash_profile

1

Actually, there is no need to set ~/.pythonrc. For Mac, one just needs to set ~/.editrc with the following content.

bind -v
bind ^I rl_complete
user1424739
  • 11,937
  • 17
  • 63
  • 152
  • 1
    You can do that, but it's going to affect a lot more than just Python if you do. That may be a good thing or a bad thing. – user2357112 Mar 15 '18 at 01:07