python完成进度百分号显示

摘要: 有时候看不到进度真的很难受,就做了个简单的进度显示器,就实现了简单功能,以后可以套用在程序里。#coding=utf-8f = open('gs.txt')w = open('gs1.txt', 'w')l = f.readlines()le = len(l)for k in range(0, le): datanow = float(k) / float(le) w.write(l[k]) print '%.2f%%' % (datanow * 100)f.close()w.close()这个打开文件,把每段文字写在另外一个文件 阅读全文
posted @ 2013-07-16 11:48 alexkh 阅读(922) 评论(0) 推荐(0) 编辑

python百度排名查询半成品

摘要: 因为编码问题卡在这里了,还是不知道咋解决。先记录下代码,明天去研究。#coding=utf-8import requestsimport BeautifulSoupimport redef createURL(checkWord): checkWord = checkWord.replace(' ', '+') checkWord = checkWord.strip() baiduURL = 'http://www.baidu.com/s?wd=%s&rn=100' % checkWord return baiduURL def getL 阅读全文
posted @ 2013-07-16 00:11 alexkh 阅读(287) 评论(0) 推荐(0) 编辑

python的Tkinter实现IP地址查询

摘要: 之前见一哥们有个不错的查询ip的API,就忍不住做了个小程序,这几天正在看Tkinter,正好试着做成软件,实用性更强一点。于是有了下面的代码:import urllib2import jsonfrom Tkinter import *root = Tk()num1 = StringVar()num2 = StringVar()num3 = StringVar()num4 = StringVar()num5 = StringVar()f1 = Frame(root, height = 50, width = 100)f1.pack()Label(f1, text = ' IP:  阅读全文
posted @ 2013-04-09 22:32 alexkh 阅读(835) 评论(0) 推荐(0) 编辑

python指定浏览器打开特定URL

摘要: import osurl = 'www.cnblogs.com'command1 = '"C:\Program Files\Internet Explorer\iexplore.exe" %s' % urlcommand2 = '"C:\Program Files\Google\Chrome\Application\chrome.exe" %s' % urlcommand3 = '"D:\Program Files\Mozilla Firefox\\firefox.exe" %s 阅读全文
posted @ 2013-04-08 22:16 alexkh 阅读(1044) 评论(0) 推荐(0) 编辑

python彩票13取9胆组程序

摘要: 是帮一个朋友做的彩票程序,也不知道有啥用,反正就是多个数字(>9)中随机取出9个,然后找出出现次数相同的5个数。具体需求如下:1、导入一组数,最多是15个2、从这组数中选出9个,所有可能的数组都列举出来3、从每个数组中统计0~9的次数4、如果有5个数出现次数相同,把这5个数列举出来,并加上出现次数;如果《5或》5,则不列举 1 import itertools 2 import csv 3 4 l = [] 5 f = open('num9.txt') 6 for n in f.readlines(): 7 n = n.strip() 8 n = int(n) 9 l.. 阅读全文
posted @ 2013-04-08 20:28 alexkh 阅读(772) 评论(0) 推荐(0) 编辑

shell脚本的sh运用

摘要: 尼玛,之前用shell时都是一行一行的敲进cygwin,看到别人写一大段的代码不知道咋运行,上周在XXOO群听他们说了下才明白,果然是鸟枪换大炮啊。1 cat g[0-9].txt | awk '{print $2, $3, $5, $7, $8, $9}' >gb.txt;2 grep '.en.$' gb.txt > gb_en.txt;3 grep ' www.$' gb.txt > gb_www.txt; 另外,每行结束都要加个“;”。这个果然好用多了。现在知道的shell指令也就这几个,以后如果如果shell编程需要再 阅读全文
posted @ 2013-04-07 13:25 alexkh 阅读(174) 评论(0) 推荐(0) 编辑

python使用IE浏览器打开指定URL

摘要: import osurl = 'www.cnblogs.com'command = '"C:\Program Files\Internet Explorer\iexplore.exe" %s' % urlos.system(command)这里的os.system可以执行系统命令,但遗憾的是只有执行,无法得到输出和返回值。要想得到输出和返回值,可以看看os.popen以及commands.getstatusoutput和commands.getoutput。这位仁兄的博客里就有这方面的例子:http://my.oschina.net/renw 阅读全文
posted @ 2013-04-07 10:02 alexkh 阅读(1164) 评论(0) 推荐(0) 编辑

Python删除列表中重复的元素

摘要: lists=[20,12,34,12,24,34,55,27]print list(set(lists))#保留原list顺序sorted(set(lists),key=lists.index)原文转自http://www.oschina.net/code/snippet_936282_19808http://www.yabogo.com/?p=565 阅读全文
posted @ 2013-04-02 12:11 alexkh 阅读(213) 评论(0) 推荐(0) 编辑

[转]python中文转换url编码

摘要: 今天要处理百度贴吧的东西。想要做一个关键词的list,每次需要时,直接添加 到list里面就可以了。但是添加到list里面是中文的情况(比如‘丽江’),url的地址编码却是'%E4%B8%BD%E6%B1%9F',因此需 要做一个转换。这里我们就用到了模块urllib。>>> import urllib>>> data = '丽江'>>> print data丽江>>> data'\xe4\xb8\xbd\xe6\xb1\x9f'>>> urllib.quo 阅读全文
posted @ 2013-03-25 16:25 alexkh 阅读(297) 评论(0) 推荐(0) 编辑

python 排列组合之itertools

摘要: python 2.6 引入了itertools模块,使得排列组合的实现非常简单:import itertools 有序排列:e.g., 4个数内选2个排列:>>> print list(itertools.permutations([1,2,3,4],2))[(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)]无序组合:e.g.,4个数内选2个:>>> print list(itertools.combinations([ 阅读全文
posted @ 2013-03-20 17:09 alexkh 阅读(13840) 评论(0) 推荐(0) 编辑