Win10(PowerShell)下Python命令行tab自动补全

Win10(PowerShell)下Python命令行tab自动补全

Python,直接通过命令行的方式进行调试简单的程序。 

win10PowerShell)奈何没有Tab补全,操作实在麻烦。

环境:win10  64  python2,python3

一:安装pyreadline模块

1

2

pip install pyreadline # python2

pip3 install pyreadline # python3

二、编写tab.py

文件保存在..\Python2\Lib\tab.py

例如:D:\Program Files\Python2\Lib\tab.py
python2
python3要使用TAb自动补全都要在对应的lib中建立tab.py文件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

#python Tab

import sys  

import readline  

import rlcompleter  

import atexit  

import os   

readline.parse_and_bind('tab: complete')  

# windows

histfile = os.path.join(os.environ['HOMEPATH'], '.pythonhistory')  

# linux

# 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

三、效果测试

使用import tab引入tab补全

# python2

Win10(PowerShell)下Python命令行tab自动补全

 

# python3

 

Win10(PowerShell)下Python命令行tab自动补全

 

# 经测试发现,python2 需要import tab 才支持自动补全,然后python3不需要导入tab就可以支持自动补全