python中 tab 键自动补全
1、新手学习python,经常要使用python命令行查找一些不熟悉的使用方法,但是python命令行下没有自带tab补全的功能,故配置如下[root@docker ~]# vim tab.py#!/usr/bin/env python# python startup fileimport sysimport readlineimport rlcompleterimport atex
·
1、使用python命令行查找不熟悉使用方法时,python命令行没有自带tab补全功能问题
[root@docker ~]# 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
2、代码有了,但还需将脚本放到python指定的目录下,可以使用sys.path来查看
>>> 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']
一般会将代码放在/usr/lib64/python2.6/site-packages目录下,可在任何目录下直接导入
>>> sys.
sys.__class__( sys.__stdout__ sys.executable sys.path
sys.__delattr__( sys.__str__( sys.exit( sys.path_hooks
sys.__dict__ sys.__subclasshook__( sys.exitfunc( sys.path_importer_cache
sys.__displayhook__( sys._clear_type_cache( sys.flags sys.platform
sys.__doc__ sys._current_frames( sys.float_info sys.prefix
sys.__excepthook__( sys._getframe( sys.getcheckinterval( sys.ps1
sys.__format__( sys.api_version
更多推荐
已为社区贡献3条内容
所有评论(0)