Python 获取按键(跨平台)class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1502浏览 457个赞
Python 验证码识别 #encoding=utf-8import Image,ImageEnhance,ImageFilterimport sysimage_name = "./22.jpeg"#去处 干扰点im = Image.open(image_name)im = im.filter(ImageFilter……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3575浏览 1923个赞
Python 随机生成中文验证码# -*- coding: utf-8 -*-import Image,ImageDraw,ImageFontimport randomimport math, string class RandomChar(): """用于随机生成汉字"""……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2525浏览 1597个赞
python gtalk机器人Python语言: python gtalk机器人# coding: utf-8## 这是根据xmpp封装的Jabber聊天机器人类, 可以通过继承,重载部分函数来自定义功能.# Jabber ID(JID): 比如gamcat@gmail.comimport xmppclass Bot: &quo……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3269浏览 2173个赞
假如有一条mongodb的记录,并不包含id字段,如果需要删除所有不包含id字段的数据,可以通过下面的代码实现。import pymongo#connect to mongodb , www.75271.comconn=pymongo.Connection()db=conn.testcollection=db.user#这条语句用于删除不包含……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2866浏览 2324个赞
windows下清理svn文件夹的python脚本# -*- coding: cp936 -*- # 注明字符集 # file:clearsvn.py 删除svn目录下的所有svn文件 import os,win32con,win32api #清除文件名头尾的引号 def trimpath(pathin): #如……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3257浏览 758个赞
Python telnet服务器 import threading class myThread(threading.Thread): def __init__(self,conn,add): threading.Thread.__init__(self) self.inputstr = '……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1952浏览 1690个赞
Python 126邮箱自动登录程序import sys, urllib2, urllib,cookielib import re cookie = cookielib.LWPCookieJar() opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) urllib2.……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3412浏览 904个赞
偷取Bing每天的桌面,并设置为自己的桌面 Python语言: 偷取Bing每天的桌面,并设置为自己的桌面# -*- coding: cp936 -*-'''Created on 2009-8-17@author: lign偷取Bing的背景图片,并设置为自己的桌面背景,随后加入预览和定时偷取'……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2540浏览 334个赞
Python 最近最少使用算法# lrucache.py -- a simple LRU (Least-Recently-Used) cache class # Copyright 2004 Evan Prodromou <evan@bad.dynu.ca> # Licensed under the Academic Free Lic……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1721浏览 963个赞
文中用到的convert.txt就是字典,但是作者的博客中没有提供下载.我通过网络搜索,从其他途径下载到了整个压缩包,包括字典和转换程序.该程序 是基于GBK的, 要把汉字分成高低位来处理,一般人理解不了,我做了点改进就是把字典转化为utf-8的,因为在django中使用的# -*- coding: utf-8 -*- # -------------……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2087浏览 367个赞
多线程Ping网段import sysimport subprocessfrom threading import Threadfrom Queue import Queueif sys.hexversion < 0x02040000: print >> sys.stderr, 'Your pytho……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2855浏览 1894个赞
Python合并文本文件# coding gbk # # author: GreatGhoul # email : greatghoul@gmail.com # blog : http://greatghoul.javaeye.com import sys,os,msvcrt def join(in_filenam……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1784浏览 414个赞
Python压缩文件夹/解压缩zip文件#coding=utf-8#甄码农python……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1670浏览 1894个赞
多线程ping和arpping扫描工具#/usr/bin/env python#--encoding=UTF-8--#auth@:xfk#blog@:blog.sina.com.cn/kaiyongdeng#data@:2012-04-15#a simpl ping scanerimport subprocessfrom threadin……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2730浏览 1388个赞
穷举法-SSH暴力破解工具#!/usr/bin/env python#-*-coding = UTF-8-*-#author@:dengyongkai#blog@:blog.sina.com.cn/kaiyongdengimport sysimport osimport time#from threading import Thread……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1914浏览 493个赞
Python 发email 带附件from email.MIMEText import MIMETextfrom email.MIMEMultipart import MIMEMultipartimport smtplibmail_host = 'smtp.126.com'mail_user = 'xx@126.……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1882浏览 2662个赞
微信-python远程控制电脑#!/etc/bin/env python#-*-encoding=utf-8-*-#auth@:dengyongkai#blog@:blog.sina.com.cn/kaiyongdengimport poplib,emailfrom email.header import decode_headerimpo……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3254浏览 854个赞
有点类似python里的timedelta,获取在指定日期上加上一段时间后的日期package mainimport ( "fmt" "time")func main() { baseTime := time.Date(1980, 1, 6, 0, 0, ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2534浏览 1188个赞
Here is a code snippet that calculates the probability of the outcome of a two sided game based on the capability of each side. I used it in my football league simulator programCo……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3064浏览 907个赞
这段python代码主要通过www.beijing-time.org的官网上获取标准的北京时间,如果你的服务器挂在网上,你可以通过这段代码定时获取北京时间,然后更新自己系统的标准时间。import time,httplibdef getBeijinTime(): try: conn = httplib.HTTPConnec……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2845浏览 1693个赞
这段代码分析网页中的所有图片表单,分析后为其前后添加相应的修饰标签,并添加到图片的超级链接。result = value.replace("[page]","").replace(' ',u' ')p=re.compile(r'''(<……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1625浏览 1617个赞
这个函数通过字符串输出startStr和endStr两个字符串时间的字符串,比如:content = “hello world”startStr = ‘h’endStr = ‘or’则返回:ello w这个函数有个小问题,就是startStr和endStr不能包含正则表达式中的……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2542浏览 703个赞
给定一个字符串,指定开头和结尾的字符串,返回中间包夹的字符串,比如:content:75271.comstartStr:endStr:返回结果:75271.comdef GetMiddleStr(content,startStr,endStr): startIndex = content.index(startStr) if……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2961浏览 799个赞
如果希望从网络读取文件进行处理,但是又不希望保存文件到硬盘,可以使用cStringIO模块进行处理res = urllib2.urlopen(pic,timeout=10)f = cStringIO.StringIO(res.read()) f 是一个文件对……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1690浏览 227个赞
re.search 和 re.matchpython提供了2中主要的正则表达式操作:re.match 和 re.search。match :只从字符串的开始与正则表达式匹配,匹配成功返回matchobject,否则返回none;search :将字符串的所有字串尝试与正则表达式匹配,如果所有的字串都没有匹配成功,返回none,否则返回matchobje……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1746浏览 1636个赞
python获得两个数组的交集、并集、差集代码转自:http://www.yihaomen.com/ 1. 获取两个list 的交集#方法一:a=[2,3,4,5]b=[2,5,8]tmp = [val for val in a if……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2441浏览 2918个赞
python根据出生日期返回年龄 def CalculateAge(self, Date): '''Calculates the age and days until next birthday from the given birth date''' t……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1923浏览 2165个赞
python通过pil生成缩略图的简单代码,这段代码会强行将图片大小修改成250×156from PIL import Imageimg = Image.open('sharejs.jpg')img = img.resize((250, 156), Image.ANTIALIAS)img.save('sha……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3064浏览 1859个赞
使用pil的蒙版功能,将原图片和圆角图片进行叠加,并将圆角图片作为mask,生成新的圆角图片转自:http://hi.baidu.com/leejun_2005/item/7ca4a7890f7af8c398255f9aflower = Image.open('flower.png')border = Image.open(……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2852浏览 336个赞
这段代码片段使用wx.lib.filebrowsebutton.FileBrowseButton控件打开一个wav文件,使用wx.Sound播放''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutt……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2739浏览 297个赞
这段代码通过urllib2打开远程图片,通过cStringIO读取文件内容,不用保存到磁盘即可读取图片文件的信息#!/usr/bin/env python#encoding=utf-8import cStringIO, urllib2, Imageurl = 'http://www.01happy.com/wp-content/up……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3368浏览 2848个赞
这段python代码看看就行,千万不要执行,否则创建了一堆无用的目录可不要怪我哟。import osimport randomdef gen(): random=rand rand.str("a", "z")direct=1while direct==1: os.mkdir(gen……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2323浏览 2399个赞
这段代码可以根据文件的完整路径返回文件名和扩展名,python的函数可以同时返回两个值,用起来就更方便了def GetFileNameAndExt(filename): import os (filepath,tempfilename) = os.path.split(filename); (shotname,extension……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2426浏览 1240个赞
这是一个简单的网络程序,可以用来扫描指定ip的常用端口from socket import *tgtHost=raw_input("What is the web address?: ")tgtPorts=raw_input("What are the ports seperated by commas? or wou……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2073浏览 978个赞
import datetimeprint(datetime.datetime.fromtimestamp(int(“1284101485”)).strftime(‘%Y-%m-%d %H:%M:%S’))import datetimeprint(datetime.datetime.fromtimest……继续阅读 » 水墨上仙 6年前 (2021-03-10) 3276浏览 841个赞
python根据出生年份计算生肖的代码,看了代码才发现原来这么简单#计算生肖def ChineseZodiac(year): return u'猴鸡狗猪鼠牛虎兔龙蛇马羊'[year%12]ChineseZodiac(1990)……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2746浏览 1771个赞
python生成指定尺寸的缩略图,先对图片进行缩小,然后进行裁剪,直到生成规定的尺寸def MakeThumb(path, sizes=(75, 32, 16)): """ 缩略图生成程序 by Neil Chen sizes 参数传递要生成的尺寸,可以生成多种尺寸 ""……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1525浏览 2471个赞
这是一组python用于验证数据是否合法的函数,包括检测类型是否为整数、浮点数、字符串、字典、元组、数组、bool类型等,还可以检测是否为货币、是否为空、是否是合法的日期格式,是否是邮件地址(Email),是否是中文字符,是否符合用户账号的规则,是否是合法的ip地址等等。#! /usr/bin/env python#coding=utf-8impo……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2329浏览 1053个赞
这段代码可以开通过个线程不断刷新指定的页面,可用于刷票,增加网页访问量等等,不用再去按F5了import threadimport urllib2import sysimport timedef usage(): print 'Usage: python ' + sys.argv[0] + ' <u……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1916浏览 1055个赞
python自定义文件查找函数,需要给定要查找的路径和文件名列表import osimport threadfrom fnmatch import fnmatch def finds(startpath,files): try: for i in os.listdir(startpath): if……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2238浏览 1607个赞
python通过mechanize模块实现不断刷新网页的功能,你可以通过命令行指定一个网页,程序将通过浏览器打开此页面并且不断的刷新,可以通过键盘随时终止,mechanize模块可以通过easy_install或者pip安装import mechanizeimport sysdef usage(): print "Usage: ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2910浏览 2709个赞
python根据月份和日得到星座#计算星座def Zodiac(month, day): n = (u'摩羯座',u'水瓶座',u'双鱼座',u'白羊座',u'金牛座',u'双子座',u'巨蟹座',u……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1695浏览 2126个赞
python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数from time import *#a function to find your agedef age(): print "Enter Your Date of Birth" d=input(&quo……继续阅读 » 水墨上仙 6年前 (2021-03-10) 2860浏览 1011个赞
python自定义的一个字典扩展类,可以让字典操作起来更简单,比如:原来需要这样用:dic[‘website’] = ‘75271.com’有了这个类,你可以这样用:dic.websites = ‘75271.com’是不是更简单。 ……继续阅读 » 水墨上仙 6年前 (2021-03-10) 1677浏览 1305个赞