首页 > 编程知识 正文

python中使用tab补全的简单介绍

时间:2023-12-27 22:27:32 阅读:326268 作者:WHNM

本文目录一览:

windows下怎么使用python3补全

1. 安装pyreadline

pip install pyreadline

2.启用tab键自动补齐

try:

import readline

except ImportError:

import pyreadline as readline

import rlcompleter

readline.parse_and_bind('tab: complete')

3.python启动自动启用自动补齐

将2.中代码保存到pythonrc.py, 并设置python.exe运行时加载pythonrc.py

set PYTHONSTARTUP=pythonrc.py

linux下的python ide怎么设置tab补全

在Python模式交互下,tab自动补全会提高代码效率,通过以下步骤可以很方便的实现自动补全。

1.获取操作目录

[root@liu site-packages]# pythonPython 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] 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'] 123456789

可以看出,我的工作目录是/usr/lib/python2.6/site-packages/。

2.进入工作目录,编写tab.py补全文件

[root@liu site-packages]# cd /usr/lib/python2.6/site-packages/[root@liu site-packages]# vim tab.py 123

tab.py内容如下,建议粘贴的时候保证格式正确性

1 #!/usr/bin/python

2 # python tab file

3 import sys 4 import readline 5 import rlcompleter 6 import atexit 7 import os 8 # tab completion

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

11 histfile = os.path.join(os.environ['HOME'], '.pythonhistory') 12 try: 13 readline.read_history_file(histfile) 14 except IOError: 15 pass

16 atexit.register(readline.write_history_file, histfile) 17

18 del os, histfile, readline, rlcompleter123456789101112131415161718

3.添加环境变量,使其生效

[root@liu site-packages]# cd [root@liu ~]# vim .bashrc123

在末尾添加一行

export PYTHONSTARTUP=/usr/lib/python2.6/site-packages/tab.py1

4.重读.bashrc文件

source .bashrc1

或者

. .bashrc1

5.测试效果

[root@liu ~]# python

Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2

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

import math math.math.__class__( math.acos( math.fsum(math.__delattr__( math.acosh( math.hypot(math.__dict__ math.asin( math.isinf(math.__doc__ math.asinh( math.isnan(math.__file__ math.atan( math.ldexp(math.__format__( math.atan2( math.log(math.__getattribute__( math.atanh( math.log10(math.__hash__( math.ceil( math.log1p(math.__init__( math.copysign( math.modf(math.__name__ math.cos( math.pimath.__new__( math.cosh( math.pow(math.__package__ math.degrees( math.radians(math.__reduce__( math.e math.sin(math.__reduce_ex__( math.exp( math.sinh(math.__repr__( math.fabs( math.sqrt(math.__setattr__( math.factorial( math.tan(math.__sizeof__( math.floor( math.tanh(math.__str__( math.fmod( math.trunc(math.__subclasshook__( math.frexp(

math.123456789101112131415161718192021222324252627

完成。我一开始一直报错,然后通过排查就是因为tab.py格式不正确。注意其格式。

怎样用vim自动补全python

Pydiction 可以是我们使用Tab键自动补全Python代码在Vim,是一款非常不错的插件。

Pydiction不需要安装,所有没有任何依赖包问题,Pydiction主要包含三个文件。

1

2

3

python_pydiction.vim -- Vim plugin that autocompletes Python code.

complete-dict -- Dictionary file of Python keywords, modules, etc.

pydiction.py -- Python script to add more words to complete-dict.

下载Pydiction

1

2

3

4

5

mkdir ~/.vim

mkidr ~/.vim/bundle

cd ~/.vim/bundle

#这里我们也可以自己下载好上传到linux系统中

git clone

配置Pydiction

1

2

3

4

#- UNIX/LINUX/OSX: Put python_pydiction.vim in ~/.vim/after/ftplugin/

#- WINDOWS: Put python_pydiction.vim in C:vimvimfilesftplugin

# Assuming you installed Vim to C:vim

cp -r ~/.vim/bundle/pydiction/after/ ~/.vim

新建.vimrc文件

1

vim ~/.vimrc

在.vimrc文件添加如下配置:

1

2

3

filetype plugin on

let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'

let g:pydiction_menu_height = 3

到此已经可以使用Tab键自动补全python代码了。

如何在vim中使用tab进行python代码补全

vi或者是vim上可以高亮显示python(也需要配置),不过没有听说过代码补全。

python编辑器中代码补全有两种,一种是根据你前面编辑的文件,提取单词,然后对你的单词做补全。这个对编码效率有提高,比如sublimetext

还有一种是它重新编译扫描了你python的lib目录下的所有库。自动进行指定库代码的指定函数或者是类的补全。这个功能相对比较弱。远远比不上java。类如eclipse上的pydev

总体来讲,python初学者最期望的是后一种代码补全。不过除了一些专业的IDE外,通常都没有这个功能。大部分python开发人员还是靠脑子记忆和查帮助知道某个类的具体方法。

python tab补全是什么意思

python是要求空格严谨。有的人需要空格时候会按两个 空格符号,有的会按左边的tab键。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。