Python 中的tab補全

來源:互聯網
上載者:User

標籤:python 中的tab補全

用Python時候沒有TAB補全,挺痛苦的,以下是添加方法


1.準備一個Python指令碼 cat > tab.py <<EOF
#!/usr/local/bin/python
# python tab 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
EOF

2.查看Python預設的模組存放位置

[[email protected] python2.7]# python
Python 2.7.6 (default, Sep 17 2017, 04:41:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']

3.拷貝到目錄下
cp tab.py /usr/local/lib/python2.7

4.現在可以用了

[[email protected] python]# cp tab.py /usr/local/lib/python2.7
[[email protected] python]# python
Python 2.7.6 (default, Sep 17 2017, 04:41:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tab
>>> import sys
>>> sys.
sys.__class__(              sys.__sizeof__(             sys.displayhook(            sys.getprofile(             sys.ps1
sys.__delattr__(            sys.__stderr__              sys.dont_write_bytecode     sys.getrecursionlimit(      sys.ps2
sys.__dict__                sys.__stdin__               sys.exc_clear(              sys.getrefcount(            sys.py3kwarning
sys.__displayhook__(        sys.__stdout__              sys.exc_info(               sys.getsizeof(              sys.setcheckinterval(
sys.__doc__                 sys.__str__(                sys.exc_type                sys.gettrace(               sys.setdlopenflags(
sys.__excepthook__(         sys.__subclasshook__(       sys.excepthook(             sys.hexversion              sys.setprofile(
sys.__format__(             sys._clear_type_cache(      sys.exec_prefix             sys.long_info               sys.setrecursionlimit(
sys.__getattribute__(       sys._current_frames(        sys.executable              sys.maxint                  sys.settrace(
sys.__hash__(               sys._getframe(              sys.exit(                   sys.maxsize                 sys.stderr
sys.__init__(               sys._mercurial              sys.exitfunc(               sys.maxunicode              sys.stdin
sys.__name__                sys.api_version             sys.flags                   sys.meta_path               sys.stdout
sys.__new__(                sys.argv                    sys.float_info              sys.modules                 sys.subversion
sys.__package__             sys.builtin_module_names    sys.float_repr_style        sys.path                    sys.version
sys.__reduce__(             sys.byteorder               sys.getcheckinterval(       sys.path_hooks              sys.version_info
sys.__reduce_ex__(          sys.call_tracing(           sys.getdefaultencoding(     sys.path_importer_cache     sys.warnoptions
sys.__repr__(               sys.callstats(              sys.getdlopenflags(         sys.platform                
sys.__setattr__(            sys.copyright               sys.getfilesystemencoding(  sys.prefix         






Python 中的tab補全

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.