一个自定义的php分页类代码<?phpclass Pagination{ // Default values var $items = -1; var $limit = NULL; var $target = ""; var $page = 1; var $adjacents = 1; var $showC……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2788浏览 971个赞
PHP定时执行任务的实现ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.set_time_limit(0);// 通过set_time_limit(0)可以让程序无限制的执行下去$interval=60*30;// 每隔半小时运行do{ //这里是你要执行的……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1443浏览 2768个赞
这段代码可以用来转换常规时间格式为unix时间戳,也可以将unix时间戳转换回来,例如:1332888820 格式转换成 2012-03-28 06:53:40的形式# -*- coding: utf-8 -*- import time def timestamp_datetime(value): format = '%Y-……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2627浏览 2705个赞
This is a simple function that runs another function in a different process by forking a new process which runs the function and waiting for the result in the parent. This can be u……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2710浏览 2952个赞
Python通过win32api递归遍历目录删除指定文件import win32conimport win32apiimport osdef del_dir(self,path): for file in os.listdir(path): file_or_dir = os.path.join(path,file) if os.pat……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2969浏览 899个赞
python从url中获取文件名import urllib2 file_name = urllib2.unquote(url).decode('utf8').split('/')[-1]……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1565浏览 1700个赞
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) 1852浏览 1652个赞
python将文本转换成图片输出#-*- coding:utf-8 -*- from PIL import Image,ImageFont,ImageDraw text = u'欢迎访问脚本分享网,http://www.75271.com' font = ImageFont.truetype("msyh……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1871浏览 1750个赞
python通过wxPython打开并播放wav文件''' wx_lib_filebrowsebutton_sound.pyselect a sound file and play itwx.lib.filebrowsebutton.FileBrowseButton(parent, labelText, fileMas……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2413浏览 1513个赞
python3 短网址和数字的相互转换import mathimport decimal def convert_to_code(num): """ 将数字转换为代码 """ def get_num(num, out=''): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2010浏览 2836个赞
python输出当前目录下的index.html文件路径import osimport sys path = os.path.join(os.path.dirname(sys.argv[0]), 'index.html')print path……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2212浏览 1168个赞
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) 3109浏览 404个赞
下面的代码通过自定义一个继承自threading.Thread的类来实现多线程编程,调用非常简单import threading import time class timer(threading.Thread): #The timer class is derived from the class threading.Thread ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1635浏览 529个赞
python通过urllib2发送带cookie的求情import urllib2opener = urllib2.build_opener()opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))f = opener.open(&quo……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1865浏览 2909个赞
这里实现的是针对网关的欺骗。假如说,你要攻击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) 2481浏览 1045个赞
python在windows下操作word的方法import win32comfrom win32com.client import Dispatch, constantsw = win32com.client.Dispatch('Word.Application')# 或者使用下面的方法,使用启动独立的进程:# w = ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2243浏览 1100个赞
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) 2159浏览 412个赞
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) 2548浏览 1450个赞
如果一个函数中所有递归形式的调用都出现在函数的末尾,我们称这个递归函数是尾递归的。当递归调用是整个函数体中最后执行的语句且它的返回值不属于表达式的一部分时,这个递归调用就是尾递归。尾递归函数的特点是在回归过程中不用做任何操作,这个特性很重要,因为大多数现代的编译器会利用这种特点自动生成优化的代码。原理当编译器检测到一个函数调用是尾递归的时候,它就覆盖当前……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2166浏览 1453个赞
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) 2264浏览 533个赞
python里用java的模块SmartXLS和jpype修改excel文件# -*- coding: utf8 -*-"""使用java的模块SmartXLS[http://www.smartxls.com/indexj.htm]和jpype修改excel和xlrd,xlwt不同的是它可以生成和保持图表"……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2400浏览 1483个赞
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) 2202浏览 2901个赞
linux下通过python获得指定网卡的ip地址import socketimport fcntlimport struct def get_ip_address(ifname): """ >>> get_ip_address('lo') '1……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1830浏览 507个赞
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) 1774浏览 628个赞
从脚本里运行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) 2311浏览 572个赞
python通过google api抓取google搜索结果,其中q参数为要搜索的关键词#!/usr/bin/python import urllib import simplejson query = urllib.urlencode({'q' : '75271.com'}) ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3194浏览 1106个赞
python通过mmap库映射文件到内存用法详解转自:http://blog.chinaunix.net/uid-20393955-id-1645587.html         &……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2889浏览 1446个赞
python编写的两个简单的文本类游戏############################################################# - My version on the game "Dragon Realm".# - taken from the book "invent with py……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2946浏览 850个赞
python通过程序向ppt文件里面插入新的幻灯片页面# -*- coding: UTF-8 -*-import win32com.clientimport win32com.client.dynamicimport os #我的範本(Template)檔名為 BugCurve.pptxdef PowerPoint(): ppt =……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2226浏览 476个赞
python通过fileinput模块逐行读取文件#------------------------------------------------------------------------------# Name: read_lines.py# Author: Kevin Harris# Last M……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2181浏览 1581个赞
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) 1592浏览 117个赞
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) 1966浏览 648个赞
时间限制:1000 ms | 内存限制:65535 KB输入两个整数a,b (0……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3147浏览 2408个赞
python中使用反射的方法import sys, types,newdef _get_mod(modulePath): try: aMod = sys.modules[modulePath] if not isinstance(aMod, types.ModuleType): ra……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3044浏览 1766个赞
下面的代码依赖于winows com,所以必须在机器上安装PowerPoint才能用,可以将PPT文件中的所有纯文本信息进行输出到指定的文件,非常实用。import win32comfrom win32com.client import Dispatch, constantsppt = win32com.client.Dispatch('……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2480浏览 1030个赞
图形类:一个很抽象的和强大的数据结构来保存许多不同种类的数据关系。#!/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) 2723浏览 2234个赞
下面的python代码演示了如何读取文件、获取读取指针的位置、从指定的位置开始读取文件#!/usr/bin/python# Open a filefo = open("/tmp/foo.txt", "r+")str = fo.read(10);print "Read String is : &……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3240浏览 129个赞
下面的代码可以为powerpoint文件ppt进行截图,可以指定要截取的幻灯片页面,需要本机安装了powerpoint,可以指定截图的大小分辨率import osimport comtypes.clientdef export_presentation(path_to_ppt, path_to_folder): if not (os.pa……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2633浏览 1178个赞
下面的代码可以给一个指定的ppt文件进行截图,可以截取任何一张幻灯片的图片,非常简单,需要本机安装了microsoft powerpoint才能使用。import win32com.clientApplication = win32com.client.Dispatch("PowerPoint.Application")Appl……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2448浏览 392个赞
random库带有一个choice方法可以从列表中随机选择一个元素mylist = ['z', 'y', 'x', 'v', 'u']from random import choiceprint choice(mylist)……继续阅读 » 水墨上仙 5年前 (2021-03-10) 4152浏览 233个赞
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) 2139浏览 2628个赞
python的pil模块可以从图片获得图片每个像素点的颜色信息,下面的代码演示了如何获取图片所有点的颜色信息和每种颜色的数量。转载请注明出处:http://www.75271.com image = Image.open("75271.com.png")image.getcolors() ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1929浏览 918个赞
删除文件夹下所有文件和子文件夹 Python语言: 删除文件夹下所有文件和子文件夹import osdef delete_file_folder(src): '''delete files and folders''' if os.path.isfile(src): ……继续阅读 » 水墨上仙 5年前 (2021-03-10) 3038浏览 2784个赞
Python解压缩zip文件,解决乱码问题 Python语言: Python解压缩zip文件,解决乱码问题#!/usr/bin/python#coding=utf8import zipfileimport sysif len(sys.argv)<2: print u'punzip zipfilename'……继续阅读 » 水墨上仙 5年前 (2021-03-10) 1492浏览 1180个赞
python的数组遍历功能非常强大,下面使用了python独有的数组操作方式将字符串数组中的所有元素的值转换成小写。print([item.lower() for item in ['ABC','SHAREJS.COM']]) 输出结果如……继续阅读 » 水墨上仙 5年前 (2021-03-10) 2775浏览 219个赞