本文目錄一覽:
- 1、windows下怎麼使用python3補全
- 2、linux下的python ide怎麼設置tab補全
- 3、怎樣用vim自動補全python
- 4、如何在vim中使用tab進行python代碼補全
- 5、python tab補全是什麼意思
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:\vim\vimfiles\ftplugin\
# 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鍵。
原創文章,作者:POZP,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/143179.html