1. 程式人生 > >python tab鍵補齊

python tab鍵補齊

python tab鍵補齊

在mac上測試


ipython
In [4]: import sys 
In [5]: sys.path
Out[5]: 
[‘‘,
 ‘/usr/local/bin‘,
 ‘/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg‘,
 ‘/Library/Python/2.7/site-packages/mysql-0.0.1-py2.7.egg‘,
 ‘/Library/Python/2.7/site-packages/ipython-3.2.1-py2.7.egg‘,
 ‘/Library/Python/2.7/site-packages/gnureadline-6.3.3-py2.7-macosx-10.8-intel.egg‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload‘,
 ‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC‘,
 ‘/Library/Python/2.7/site-packages‘,
 ‘/Library/Python/2.7/site-packages/ipython-3.2.1-py2.7.egg/IPython/extensions‘,
 ‘/private/var/root/.ipython‘]


代碼有了,我們還需要將腳本放到python指定的目錄下,可以使用sys.path來查看一下

(linux服務器):一般我們會將這一類代碼放在/usr/local/lib/python2.7/dist-packages目錄下

(MAC存放在這個目錄下)/Library/Python/2.7/site-packages

admindeMacBook-Air-62:site-packages admin$ vim tab.py 
#!/usr/bin/env 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


代碼中就可以import tab了

In [11]: import tab
In [12]: sys.
sys.__class__(              sys.__setattr__(            sys.displayhook(            sys.getrecursionlimit(      sys.prefix
sys.__delattr__(            sys.__sizeof__(             sys.dont_write_bytecode     sys.getrefcount(            sys.ps1
sys.__dict__                sys.__stderr__              sys.exc_clear(              sys.getsizeof(              sys.ps2
sys.__displayhook__(        sys.__stdin__               sys.exc_info(               sys.gettrace(               sys.ps3
sys.__doc__                 sys.__stdout__              sys.exc_type                sys.hexversion              sys.py3kwarning
sys.__egginsert             sys.__str__(                sys.excepthook(             sys.last_traceback          sys.setcheckinterval(
sys.__excepthook__(         sys.__subclasshook__(       sys.exec_prefix             sys.last_type(              sys.setdlopenflags(
sys.__format__(             sys._clear_type_cache(      sys.executable              sys.last_value              sys.setprofile(
sys.__getattribute__(       sys._current_frames(        sys.exit(                   sys.long_info               sys.setrecursionlimit(
sys.__hash__(               sys._getframe(              sys.exitfunc(               sys.maxint                  sys.settrace(
sys.__init__(               sys._mercurial              sys.flags                   sys.maxsize                 sys.stderr
sys.__name__                sys.api_version             sys.float_info              sys.maxunicode              sys.stdin
sys.__new__(                sys.argv                    sys.float_repr_style        sys.meta_path               sys.stdout
sys.__package__             sys.builtin_module_names    sys.getcheckinterval(       sys.modules                 sys.subversion
sys.__plen                  sys.byteorder               sys.getdefaultencoding(     sys.path                    sys.version
sys.__reduce__(             sys.call_tracing(           sys.getdlopenflags(         sys.path_hooks              sys.version_info
sys.__reduce_ex__(          sys.callstats(              sys.getfilesystemencoding(  sys.path_importer_cache     sys.warnoptions
sys.__repr__(               sys.copyright               sys.getprofile(             sys.platform 

In [12]: sys.





本文出自 “梅花香自苦寒來!” 博客,請務必保留此出處http://daixuan.blog.51cto.com/5426657/1934112

python tab鍵補齊