python中带有zlib库可以用来对数据进行压缩和解压缩,针对大量数据可以节省不少的空间import zlibdata='hello world'data = zlib.compress(data)#压缩#data此时的值为:'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2285浏览 2459个赞
python将文本转换成图片输出#-*- coding:utf-8 -*- from PIL import Image,ImageFont,ImageDraw text = u'欢迎访问脚本分享网,http://www.75271.com' font = ImageFont.truetype("msyh……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1853浏览 1181个赞
python通过wxPython打开并播放wav文件''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutton.FileBrowseButton(parent, labelText, fileMas……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2013浏览 1722个赞
python3 短网址和数字的相互转换import mathimport decimal def convert_to_code(num): """ 将数字转换为代码 """ def get_num(num, out=''): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1489浏览 214个赞
python输出当前目录下的index.html文件路径import osimport sys path = os.path.join(os.path.dirname(sys.argv[0]), 'index.html')print path……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2363浏览 1640个赞
python删除列表中的重复记录def removeListDuplicates(seq): seen = set() seen_add = seen.add return [ x for x in seq if x not in seen and not seen_add(x) ]……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2414浏览 2272个赞
下面的代码通过自定义一个继承自threading.Thread的类来实现多线程编程,调用非常简单import threading import time class timer(threading.Thread): #The timer class is derived from the class threading.Thread ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2942浏览 716个赞
python通过urllib2发送带cookie的求情import urllib2opener = urllib2.build_opener()opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))f = opener.open(&quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3101浏览 2124个赞
这里实现的是针对网关的欺骗。假如说,你要攻击A机器,其IP是192.168.1.100,MAC是aa:bb:cc:dd:ee:ff,这样你就可以发给网关一个伪造包,包的源IP为192.168.1.100,源MAC为00:11:22:33:44:55,这样就实现对了网关的欺骗。转自:http://www.cnblogs.com/lovedboy/#co……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3323浏览 2917个赞
python在windows下操作word的方法import win32comfrom win32com.client import Dispatch, constantsw = win32com.client.Dispatch('Word.Application')# 或者使用下面的方法,使用启动独立的进程:# w = ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2061浏览 2480个赞
python arp欺骗伪造网关代码转自:http://www.cnblogs.com/lovedboy/#coding:utf-8'''arp欺骗局域网pc,将伪造的网关mac以网关的arp应答发送给pc'''from scapy.all import ARP,send,arpin……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3272浏览 517个赞
python通过win32com打开word,excel,ppt,并控制其最大化、最小化显示import win32com.clientw=win32com.client.Dispatch("Word.Application")w.Visible=True #控制word显示w.WindowState = 1 #1表示正常,2……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2866浏览 2767个赞
如果一个函数中所有递归形式的调用都出现在函数的末尾,我们称这个递归函数是尾递归的。当递归调用是整个函数体中最后执行的语句且它的返回值不属于表达式的一部分时,这个递归调用就是尾递归。尾递归函数的特点是在回归过程中不用做任何操作,这个特性很重要,因为大多数现代的编译器会利用这种特点自动生成优化的代码。原理当编译器检测到一个函数调用是尾递归的时候,它就覆盖当前……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2838浏览 786个赞
python从网络下载文件并获得文件大小、文件类型import urllib2from settings import COOKIES opener = urllib2.build_opener() cookies = ";".join("%s=%s" % (k, v) for k, v in COO……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1505浏览 1952个赞
python里用java的模块SmartXLS和jpype修改excel文件# -*- coding: utf8 -*-"""使用java的模块SmartXLS[http://www.smartxls.com/indexj.htm]和jpype修改excel和xlrd,xlwt不同的是它可以生成和保持图表"……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3225浏览 1003个赞
python Web 框架bottle超清晰使用范例,通过这个范例你可以大概了解bottle是如何使用的#coding: utf-8from bottle import route, error, post, get, run, static_file, abort, redirect, response, request, template@r……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1977浏览 2900个赞
linux下通过python获得指定网卡的ip地址import socketimport fcntlimport struct def get_ip_address(ifname): """ >>> get_ip_address('lo') '1……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1836浏览 378个赞
python将pvr格式转换成pvr.cczimport zlibimport structimport syspvr = sys.argv[1]ccz = pvr + ".ccz"pvr = open(pvr).read()ccz = open(ccz, "wb")ccz.write(str……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2566浏览 816个赞
从脚本里运行scrapy的代码# This snippet can be used to run scrapy spiders independent of scrapyd or the scrapy command line tool and use it from a script. # # The multiprocessing librar……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3038浏览 269个赞
python通过google api抓取google搜索结果,其中q参数为要搜索的关键词#!/usr/bin/python import urllib import simplejson query = urllib.urlencode({'q' : '75271.com'}) ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2761浏览 1686个赞
python通过mmap库映射文件到内存用法详解转自:http://blog.chinaunix.net/uid-20393955-id-1645587.html         &……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1645浏览 1028个赞
python编写的两个简单的文本类游戏############################################################# - My version on the game "Dragon Realm".# - taken from the book "invent with py……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2819浏览 2576个赞
python通过程序向ppt文件里面插入新的幻灯片页面# -*- coding: UTF-8 -*-import win32com.clientimport win32com.client.dynamicimport os #我的範本(Template)檔名為 BugCurve.pptxdef PowerPoint(): ppt =……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1871浏览 2155个赞
python通过fileinput模块逐行读取文件#------------------------------------------------------------------------------# Name: read_lines.py# Author: Kevin Harris# Last M……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2102浏览 2198个赞
python控制随机间隔一段时间发送邮件、消息或弹出窗口""" If you need to do something irregularly, randomly during the weekday, youoften forget. This script gives you mail, sms or popup w……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2365浏览 1085个赞
python scrapy 网络采集使用代理的方法 1.在Scrapy工程下新建“middlewares.py”# Importing base64 library because we'll need it ONLY in case if the proxy we ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2152浏览 1573个赞
时间限制:1000 ms | 内存限制:65535 KB输入两个整数a,b (0……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1671浏览 656个赞
python中使用反射的方法import sys, types,newdef _get_mod(modulePath): try: aMod = sys.modules[modulePath] if not isinstance(aMod, types.ModuleType): ra……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3363浏览 2937个赞
下面的代码依赖于winows com,所以必须在机器上安装PowerPoint才能用,可以将PPT文件中的所有纯文本信息进行输出到指定的文件,非常实用。import win32comfrom win32com.client import Dispatch, constantsppt = win32com.client.Dispatch('……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2001浏览 835个赞
图形类:一个很抽象的和强大的数据结构来保存许多不同种类的数据关系。#!/usr/bin/env python# (c) Mark Janssen, this file is licensed under the GNU General Public License v2 found at <http://www.gnu.org/licenses……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2636浏览 614个赞
下面的python代码演示了如何读取文件、获取读取指针的位置、从指定的位置开始读取文件#!/usr/bin/python# Open a filefo = open("/tmp/foo.txt", "r+")str = fo.read(10);print "Read String is : &……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3188浏览 957个赞
下面的代码可以为powerpoint文件ppt进行截图,可以指定要截取的幻灯片页面,需要本机安装了powerpoint,可以指定截图的大小分辨率import osimport comtypes.clientdef export_presentation(path_to_ppt, path_to_folder): if not (os.pa……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1780浏览 2108个赞
下面的代码可以给一个指定的ppt文件进行截图,可以截取任何一张幻灯片的图片,非常简单,需要本机安装了microsoft powerpoint才能使用。import win32com.clientApplication = win32com.client.Dispatch("PowerPoint.Application")Appl……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3161浏览 1981个赞
random库带有一个choice方法可以从列表中随机选择一个元素mylist = ['z', 'y', 'x', 'v', 'u']from random import choiceprint choice(mylist)……继续阅读 » 水墨上仙 5年前 (2021-03-10) 4095浏览 2181个赞
python使用append合并两个数组lista = [1,2,3]listb = [4,5,6] mergedlist =[]for elem in lista: mergedlist.append(elem)for elem in listb: mergedlist.append(elem)……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3502浏览 1750个赞
python的pil模块可以从图片获得图片每个像素点的颜色信息,下面的代码演示了如何获取图片所有点的颜色信息和每种颜色的数量。转载请注明出处:http://www.75271.com image = Image.open("75271.com.png")image.getcolors() ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1657浏览 1227个赞
删除文件夹下所有文件和子文件夹 Python语言: 删除文件夹下所有文件和子文件夹import osdef delete_file_folder(src): '''delete files and folders''' if os.path.isfile(src): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3400浏览 1453个赞
Python解压缩zip文件,解决乱码问题 Python语言: Python解压缩zip文件,解决乱码问题#!/usr/bin/python#coding=utf8import zipfileimport sysif len(sys.argv)<2: print u'punzip zipfilename'……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3269浏览 162个赞
python的数组遍历功能非常强大,下面使用了python独有的数组操作方式将字符串数组中的所有元素的值转换成小写。print([item.lower() for item in ['ABC','SHAREJS.COM']]) 输出结果如……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2790浏览 1586个赞
heapq是一个很好的堆类,但是其自带的方法不太明确,这里自定义了一个heap类import heapqclass heap(list) : def __init__(self, * pos_arg, ** nam_arg) : list.__init__(self, * pos_arg, ** nam_arg) def pop(se……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3045浏览 268个赞
Python 获取按键(跨平台)class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3424浏览 102个赞
Python 验证码识别 #encoding=utf-8import Image,ImageEnhance,ImageFilterimport sysimage_name = "./22.jpeg"#去处 干扰点im = Image.open(image_name)im = im.filter(ImageFilter……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2153浏览 2383个赞
Python 随机生成中文验证码# -*- coding: utf-8 -*-import Image,ImageDraw,ImageFontimport randomimport math, string class RandomChar(): """用于随机生成汉字"""……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1876浏览 2965个赞
python gtalk机器人Python语言: python gtalk机器人# coding: utf-8## 这是根据xmpp封装的Jabber聊天机器人类, 可以通过继承,重载部分函数来自定义功能.# Jabber ID(JID): 比如gamcat@gmail.comimport xmppclass Bot: &quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3195浏览 2184个赞
假如有一条mongodb的记录,并不包含id字段,如果需要删除所有不包含id字段的数据,可以通过下面的代码实现。import pymongo#connect to mongodb , www.75271.comconn=pymongo.Connection()db=conn.testcollection=db.user#这条语句用于删除不包含……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2338浏览 2741个赞