您的位置:首页 > 编程语言 > Python开发

Python 命令自动补全

2016-04-28 11:32 585 查看
学习python再import模块时,对模块有时候不太了解的,就需要看看此模块有那些命令。
1.创建tar.py文件
[root@nginx-master python2.6]# cat tar.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
[root@nginx-master python2.6]#
2,查看一下模块相关文件的存取位置并把刚刚创建的tar.py文件移动指定位置
[root@nginx-master python2.6]# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "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/gtk-2.0', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
移动文件到指定位置
[root@nginx-master python2.6]# mv tar.py /usr/lib64/python2.6/
到此结束,让我测试一下命令补全的快感吧!
[root@nginx-master python2.6]# python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tar
>>> import os
>>> os.
Display all 244 possibilities? (y or n) #列出OS.所支持的全部命令的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  file python import