python命令行tab自动补齐

为什么80%的码农都做不了架构师?>>>   hot3.png

windows,放在python的lib库目录下编辑tab.py

#!/usr/bin/python
#python startup file
import sys
import readline
import rlcompleter
import atexit
import os
#tab completion
readline.parse_and_bind('tab: complete')
#history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
    readline.read_history_file(histfile)
except IOError:
    pass
atexit.register(readline.write_history_file,histfile)
del os, histfile, readline, rlcompleter

mac

#!/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

使用import tab

转载于:https://my.oschina.net/u/1775013/blog/2221506

你可能感兴趣的:(python命令行tab自动补齐)