码迷,mamicode.com
首页 > 编程语言 > 详细

Mac系统之Python命令行tab键补全

时间:2016-06-21 08:07:36      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:mac   命令行   python   补全   

新建~/.pythonstartup文件并写入以下内容:

$ cat ~/.pythonstartup 
import sys
import readline
import rlcompleter

if sys.platform == ‘darwin‘ and sys.version_info[0] == 2:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")


然后设置环境变量PYTHONSTARTUP,可以在家目录的~/.bash_profile文件中进行设置,追加如下一行。如下:

export PYTHONSTARTUP=$HOME/.pythonstartup


重新加载~/.bash_profile配置文件,

. ~/.bash_profile


设置完毕,可以进入python的命令行终端,进行验证是否可以进行tab键补全,

 python
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.1.7 Compatible Apple LLVM 6.8.0 (clang-500.0.11.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.p
sys.path                sys.platform            sys.ps2                
sys.path_hooks          sys.prefix              sys.py3kwarning        
sys.path_importer_cache sys.ps1                
>>> print sys.p


好了,经过验证是可以进行补全的。

本文出自 “固态U盘” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1791183

Mac系统之Python命令行tab键补全

标签:mac   命令行   python   补全   

原文地址:http://lavenliu.blog.51cto.com/5060944/1791183

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!