网络编程
位置:首页>> 网络编程>> Python编程>> Python (Win)readline和tab补全的安装方法

Python (Win)readline和tab补全的安装方法

作者:x024  发布时间:2021-07-30 16:04:46 

标签:Python,readline,tab补全

最近开始学Python,想直接通过命令行的方式进行学习。

奈何没有Tab补全,操作实在麻烦,网上各种百度后无果(x64系统,x86的可以直接下载网上各种编译好的包)

最后自己百度+加上自己的摸索,找到了在64位系统下轻松安装readline和tab补全的方法

一、安装readline

cmd命令行,就会自动安装readline模块


python -m pip install pyreadline

Python (Win)readline和tab补全的安装方法

二、编写tab.py

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

例如:D:\Program Files\Python\Lib\tab.py


#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补全

import tab

Python (Win)readline和tab补全的安装方法

四、常见问题

1. 同时安装python2.7 + python3.0

安装readline时使用:


python -2 -m pip install pyreadline

2. 提示readline不是DLL %1

请使用Python提供的命令安装,我就是下载网上编译好的readline模块就有这个问题。(使用第一步)

来源:https://blog.csdn.net/hx7013/article/details/63871940

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com