python如何嵌入按键_python添加tab键功能

学习Python的时候,如何没有tab键补全功能,我感觉那将是一个噩梦,对于我们这种菜鸟来说,刚接触python,对一切都不了解,还好有前辈们的指导,学习一下,并记录下来,还没有学习这个功能小伙伴们!

环境:

[root@localhost ~]# cat /etc/centos-release

CentOS Linux release 7.4.1708 (Core)

[root@localhost ~]#

具体过程:

[root@localhost site-packages]#python          #进入python

Python 2.7.5 (default, Aug 4 2017, 00:39:18)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>import sys                                                 #导入sys模块

>>>sys.path                                                    #确认系统默认撸觉

['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages']

>>> exit()

[root@localhost site-packages]# pwd              #进入要放入tab.py文件的目录(上面的路径,随便放一个),我防止如下目录:

/usr/lib64/python2.7/site-packages

###########################################################

[root@localhost site-packages]# cat tab.py

#!/usr/bin/python#python tab complete

importsysimportreadlineimportrlcompleterimportatexitimportos#tab completion

readline.parse_and_bind('tab: complete')#history file

histfile = os.path.join(os.environ['HOME'], '.pythonhistory')try:

readline.read_history_file(histfile)exceptIOError:passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter

###########################################################

[root@localhost site-packages]# python

Python 2.7.5 (default, Aug 4 2017, 00:39:18)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import tab                  #使用前先导入tab模块

>>> import sys                  #下面就可以使用tab键了

>>> sys.

sys.__class__( sys.__sizeof__( sys.copyright sys.getfilesystemencoding( sys.prefix

sys.__delattr__( sys.__stderr__ sys.displayhook( sys.getprofile( sys.ps1

sys.__dict__ sys.__stdin__ sys.dont_write_bytecode sys.getrecursionlimit( sys.ps2

sys.__displayhook__( sys.__stdout__ sys.exc_clear( sys.getrefcount( sys.py3kwarning

sys.__doc__ sys.__str__( sys.exc_info( sys.getsizeof( sys.pydebug

sys.__excepthook__( sys.__subclasshook__( sys.exc_type sys.gettrace( sys.setcheckinterval(

sys.__format__( sys._clear_type_cache( sys.excepthook( sys.hexversion sys.setdlopenflags(

sys.__getattribute__( sys._current_frames( sys.exec_prefix sys.long_info sys.setprofile(

sys.__hash__( sys._debugmallocstats( sys.executable sys.maxint sys.setrecursionlimit(

sys.__init__( sys._getframe( sys.exit( sys.maxsize sys.settrace(

sys.__name__ sys._mercurial sys.exitfunc( sys.maxunicode sys.stderr

sys.__new__( sys.api_version sys.flags sys.meta_path sys.stdin

sys.__package__ sys.argv sys.float_info sys.modules sys.stdout

sys.__reduce__( sys.builtin_module_names sys.float_repr_style sys.path sys.subversion

sys.__reduce_ex__( sys.byteorder sys.getcheckinterval( sys.path_hooks sys.version

sys.__repr__( sys.call_tracing( sys.getdefaultencoding( sys.path_importer_cache sys.version_info

sys.__setattr__( sys.callstats( sys.getdlopenflags( sys.platform sys.warnoptions

>>> sys.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值