mac 终端python tab键自动补全(亲测可以)

#!/usr/bin/env python
# encoding: utf-8

import readline,rlcompleter

[size=16]# Indenting
[/size]
class TabCompleter(rlcompleter.Completer):
    """Completer that supports indenting"""
    def complete(self, text, state):
        if not text:
            return ('    ', None)[state]
        else:
            return rlcompleter.Completer.complete(self, text, state)

readline.set_completer(TabCompleter().complete)

[size=16]# Add autocompletion
[/size]
if 'libedit' in readline.__doc__:
    readline.parse_and_bind("bind -e")
    readline.parse_and_bind("bind '\t' rl_complete")
else:
    readline.parse_and_bind("tab: complete")

[size=16]# Add history
[/size]
import os
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
    readline.read_history_file(histfile)
except IOError:
    pass
import atexit
atexit.register(readline.write_history_file, histfile)
del histfile
[attach]968[/attach]

0 个评论

要回复文章请先登录注册