给Python IDLE加上自动补全和历史功能

redswallow posted @ Sun, 23 May 2010 22:03:41 +0800 in python , 7928 readers

许多时候,我们使用Python,并不用写一个程序,一些不复杂的任务,我更喜欢在 IDLE(也就是交互式提示模式)下输入几行代码完成。然而,在这个模式下编辑代码,也有不够便利的地方,最主要的就是,不能用Tab自动补全,不能记忆 上一次输入的命令(没办法,谁让我们在Shell下习惯了呢)。
这时候,我们可以直接使用Python启动脚本,解决这个问题。

启动脚本的程序非常简单,这里不多说明,只给出代码:

import readline
import rlcompleter
import atexit
import os
# tab autocomplete
readline.parse_and_bind(‘tab: complete’)
# history file
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

 完成之后,我们把它保存为.pythonstartup,存放在自己的目录下(譬如/home/yurii),再将PYTHONSTARTUP变量指向刚才放的地址,就可以了。最省事的办法是在bashrc中添加这样一行: 

export PYTHONSTARTUP=/home/yurii/.pythonstartup

 这样,不但增加了tab的自动补全功能,而且重新启动IDLE时,通过上下键,还能翻到上次输入的命令,非常方便。

 

Avatar_small
ningyu said:
Mon, 17 Jun 2013 11:06:10 +0800

lz试试alt+p,alt+n,http://forum.ubuntu.org.cn/viewtopic.php?t=249852

Avatar_small
Landon Jackson said:
Fri, 25 Jan 2019 19:18:31 +0800

Appreciate it intended for giving new messages the matter, When i count on understand far more. Tax Advice

Avatar_small
Gay Tube said:
Thu, 16 Apr 2020 22:33:44 +0800

Very nice blog and articles. I am realy very happy to visit your blog. Now I am found which I actually want. I check your blog everyday and try to learn something from your blog. Thank you and waiting for your new post.

Avatar_small
123mvoies said:
Thu, 28 May 2020 16:54:38 +0800

movie drama site online https://123movies7.com

Avatar_small
free sexting website said:
Mon, 15 Jun 2020 01:31:18 +0800

I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge.

Avatar_small
artes para mídias so said:
Sat, 27 Jun 2020 06:54:12 +0800

Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me

Avatar_small
kings lynn nightclub said:
Sat, 04 Jul 2020 04:29:48 +0800

Well everything has some pros and cons but its upto us that how we handle kings lynn nightclubs challenges because its always how do we respond to things.

Avatar_small
bigcommerce data ent said:
Wed, 08 Jul 2020 04:06:58 +0800

I really thank you for the valuable info on this great subject and look forward to more great posts

Avatar_small
Safir Painting said:
Sat, 08 Aug 2020 16:03:15 +0800

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing.

Avatar_small
oferty pracy said:
Fri, 21 Aug 2020 01:28:08 +0800

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well..

Avatar_small
job posting said:
Sat, 22 Aug 2020 21:07:49 +0800

I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site.

Avatar_small
Immobilien Franchise said:
Thu, 27 Aug 2020 02:17:44 +0800

Only a few blogger would discuss this topic the way you do.’.”`:

Avatar_small
Dj animation de mari said:
Sun, 13 Sep 2020 18:58:41 +0800

Im using a tiny problem I cant subscribe your feed, Im using google reader fyi.

Avatar_small
hansestadt bremen im said:
Wed, 30 Sep 2020 19:54:42 +0800

I am not afraid to find this but this is just insane.

Avatar_small
pak24tv said:
Mon, 05 Oct 2020 20:27:33 +0800

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. top 10 richest countries in the world top 10 poorest countries in the world top 10 most beautiful places in the world

Avatar_small
QHS Development said:
Tue, 06 Oct 2020 00:18:37 +0800

you have a great weblog here! do you need to have invite posts in my blog?

Avatar_small
RajaQQ said:
Thu, 22 Oct 2020 17:58:11 +0800

As a seller of legal steroids, you can buy Crazy Bulk products, explore stacks and finally get the body you’ve always wanted

Avatar_small
escort said:
Wed, 28 Oct 2020 01:38:18 +0800

This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this..

Avatar_small
chiangmai termite said:
Fri, 30 Oct 2020 22:04:58 +0800

กำจัดปลวกเชียงใหม่ ( chiangmai termite ) เป็นบริษัทกำจัดปลวกเชียงใหม่ ฉีดปลวกเชียงใหม่ราคาถูก เน้นความคุ้มค่า เพื่อลดค่าใช้จ่ายของลูกค้า. มีขั้นตอนการฉีดปลวกเหมือนกับบริษัทใหญ่ราคาแพง.เรารับงานทุกตำบล ทุกอำเภอ ในเชียงใหม่ , อำเภอเมืองเชียงใหม่ , ศรีภูมิ , พระสิงห์ , หายยา , ช้างม่อย , ช้างคลาน , วัดเกต , ช้างเผือก , สุเทพ , แม่เหียะ , ป่าแดด , หนองหอย , ท่าศาลา , หนองป่าครั่ง , ฟ้าฮ่าม , ป่าตัน , สันผีเสื้อ , อำเภอจอมทอง , อำเภอเชียงดาว , อำเภอดอยสะเก็ด , อำเภอแม่ริม , อำเภอสะเมิง , อำเภอฝาง , อำเภอแม่อาย , อำเภอพร้าว , อำเภอสันป่าตอง , อำเภอสันกำแพง , อำเภอสันทราย , สันทรายหลวง , สันทรายน้อย , สันพระเนตร , สันนาเม็ง , สันป่าเปา , หนองแหย่ง , หนองจ๊อม , หนองหาร , แม่แฝก , แม่แฝกใหม่ , เมืองเล็น , ป่าไผ่ , อำเภอหางดง , หางดง , หนองแก๋ว , หารแก้ว , หนองตอง , ขุนคง , สบแม่ข่า , บ้านแหวน , สันผักหวาน , หนองควาย , บ้านปง , น้ำแพร่ , อำเภอฮอด , อำเภอดอยเต่า , อำเภออมก๋อย , อำเภอเวียงแหง , อำเภอไชยปราการ , อำเภอแม่วาง , อำเภอแม่ออน , อำเภอดอยหล่อ , อำเภอกัลยาณิวัฒนา ,

Avatar_small
Escort San Diego said:
Sun, 08 Nov 2020 06:33:40 +0800

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.

Avatar_small
ROXEN said:
Wed, 11 Nov 2020 02:07:37 +0800

It’s really a fantastic website, thanks for sharing. There's no doubt i would fully rate it after i read what the idea about this article is. You did a nice صيانة غسالات

Avatar_small
check benefits said:
Fri, 13 Nov 2020 04:59:17 +0800

Cool stuff you have and you keep overhaul every one of us

Avatar_small
Glock 17 for sale said:
Tue, 24 Nov 2020 19:00:14 +0800

You have done a amazing job with you website

Avatar_small
bible verses said:
Sat, 28 Nov 2020 19:25:37 +0800

Great survey. I'm sure you're getting a great response.

Avatar_small
bible verses said:
Sat, 28 Nov 2020 20:18:59 +0800

I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work

Avatar_small
polskie kasyno onlin said:
Sat, 05 Dec 2020 22:44:09 +0800

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.

Avatar_small
android video editor said:
Sat, 12 Dec 2020 19:41:38 +0800

I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge.

Avatar_small
สล็อต xo said:
Thu, 17 Dec 2020 22:01:08 +0800 Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. สล็อต xo
Avatar_small
Robinjack said:
Mon, 21 Dec 2020 18:32:00 +0800

nice blog and really nice post. i like it. make a fanpage on facebook. mobile form development

Avatar_small
no excuses runner said:
Mon, 04 Jan 2021 14:37:32 +0800

This blog was extremely helpful. I really appreciate your kindness in sharing this with me and everyone else! Betfair vedonlyöntibonus

Avatar_small
Resistance bands said:
Tue, 05 Jan 2021 21:38:09 +0800

Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me. Resistance bands

Avatar_small
Best Portable Blueto said:
Wed, 06 Jan 2021 14:20:41 +0800

Incredible articles and awesome design. Your blog entry merits the greater part of the positive input it"s been getting. Best Portable Bluetooth Speaker

Avatar_small
Lsd said:
Wed, 06 Jan 2021 19:05:37 +0800

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks. Lsd

Avatar_small
Hemstädning i Malmö said:
Fri, 08 Jan 2021 01:46:31 +0800

One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run.  Hemstädning i Malmö

Avatar_small
kasyno online blik said:
Thu, 14 Jan 2021 22:21:26 +0800

First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics, i will be always checking your blog thanks.

Avatar_small
kasyno online said:
Sun, 17 Jan 2021 01:33:31 +0800

I have bookmarked your website because this site contains valuable information in it. I am really happy with articles quality and presentation. Thanks a lot for keeping great stuff. I am very much thankful for this site.

Avatar_small
polskie kasyno onlin said:
Sun, 17 Jan 2021 22:59:35 +0800

The blog and data is excellent and informative as well

Avatar_small
ryse residences cond said:
Sat, 23 Jan 2021 21:06:22 +0800

At We Walk Together L LC, we are dedicated to providing patients with the best possible care. We at WE WALK TOGETHER LLC are focused on helping you. <a href="https://www.wewalktogetherllc.com/">Telehealth</a>


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter