新手学习Python的时候,如何没有tab键补全功能,我感觉那将是一个噩梦,对于我们这种菜鸟来说,刚接触python,对一切都不了解,还好有前辈们的指导,学习一下,并记录下来,还没有学习这个功能小伙伴们!赶紧get吧!
[root@localhost ~]# pythonPython 2.6.6 (r266:84292, Oct 12 2012, 14:23:48) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path["", "/usr/lib64/python26.zip", "/usr/lib64/python2.6", "/usr/lib64/python2.6/plat-linux2", "/usr/lib64/python2.6/lib-tk", "/usr/lib64/python2.6/lib-old", "/usr/lib64/python2.6/lib-dynload", "/usr/lib64/python2.6/site-packages", "/usr/lib64/python2.6/site-packages/gst-0.10", "/usr/lib64/python2.6/site-packages/gtk-2.0", "/usr/lib64/python2.6/site-packages/webkit-1.0", "/usr/lib/python2.6/site-packages"]- 切换目录到python的安装目录下,进行tab键补全模块的编写。
[root@localhost ~]# cd /usr/lib64/python2.6[root@localhost python2.6]# vim tab.py#!/usr/bin/env python # python startup file import sysimport readlineimport rlcompleterimport atexitimport 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:passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter- 此处我们编写完成后就可以进入python中导入tab键补全
root@localhost python2.6]# pythonPython 2.6.6 (r266:84292, Oct 12 2012, 14:23:48) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import tab>>> sys.sys.__class__(sys.__reduce_ex__(sys.builtin_module_namessys.exitfunc( sys.maxsize sys.setprofile(sys.__delattr__(sys.__repr__( sys.byteorder sys.flags sys.maxunicodesys.setrecursionlimit(sys.__dict__sys.__setattr__(sys.call_tracing( sys.float_infosys.meta_path sys.settrace(sys.__displayhook__(sys.__sizeof__( sys.callstats(sys.getcheckinterval( sys.modules sys.stderrsys.__doc__ sys.__stderr__sys.copyright sys.getdefaultencoding( sys.pathsys.stdinsys.__excepthook__( sys.__stdin__ sys.displayhook(sys.getdlopenflags( sys.path_hookssys.stdoutsys.__format__( sys.__stdout__sys.dont_write_bytecode sys.getfilesystemencoding(sys.path_importer_cache sys.subversionsys.__getattribute__( sys.__str__(sys.exc_clear(sys.getprofile( sys.platformsys.versionsys.__hash__( sys.__subclasshook__( sys.exc_info( sys.getrecursionlimit(sys.prefixsys.version_infosys.__init__( sys._clear_type_cache(sys.exc_typesys.getrefcount(sys.ps1 sys.warnoptionssys.__name__sys._current_frames(sys.excepthook( sys.getsizeof(sys.ps2 sys.__new__(sys._getframe(sys.exec_prefix sys.gettrace( sys.py3kwarning sys.__package__ sys.api_version sys.executablesys.hexversionsys.setcheckinterval( sys.__reduce__( sys.argvsys.exit( sys.maxintsys.setdlopenflags( - 为了进入python之后不用每次都导入,来进行下边的操作,进入家目录,编写 .bashrc文件在最后添加下面一行,保存退出。
[root@localhost ~]# cd ~[root@localhost ~]# vim .bashrcexport PYTHONSTARTUP=/usr/lib64/python2.6/tab.py- 家目录.bashrc文件只有用户登录时才会加载生效,需要进行下面的操作来生效
[root@localhost ~]# source .bashrc OK,那么现在我们就可以不用每次进行python之后进行import tab 动作来使tab键补全功能生效了。CentOS上源码安装Python3.4 http://www.linuxidc.com/Linux/2015-01/111870.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm
《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htm
Python 的详细介绍:请点这里
Python 的下载地址:请点这里
本文永久更新链接地址