常见的排序算法:冒泡排序,选择排序,插入排序,希尔排序,快速排序,堆排序,归并排序。冒泡排序原理:两两元素进行比较,每一趟能够确定最大元素的位置,稳定算法defbubble_sort(alist):'''冒泡排序'''#[5,4,3,2,1][4,5,3,2,1][4,3,5,2,1][4,3,2,5,1][4,3,2,1,5]n=len(alist)foriinrange(n):#count=0forjinrange(0,n-1):ifalist[j]>
系统 2019-09-27 17:49:28 2140
Python重试模块retrying工作中经常碰到的问题就是,某个方法出现了异常,重试几次。循环重复一个方法是很常见的。比如爬虫中的获取代理,对获取失败的情况进行重试。刚开始搜的几个博客讲的有点问题,建议看官方文档,还有自己动手实验。参考:https://segmentfault.com/a/1190000004085023https://pypi.org/project/retrying/最初的版本importrequestsclassProxyUtil
系统 2019-09-27 17:49:24 2140
脚本如下:fromopenpyxlimportload_workbookworkbook=load_workbook(u'/tmp/test.xlsx')#找到需要xlsx文件的位置booksheet=workbook.active#获取当前活跃的sheet,默认是第一个sheet#如果想获取别的sheet页采取下面这种方式,先获取所有sheet页名,在通过指定那一页。#sheets=workbook.get_sheet_names()#从名称获取shee
系统 2019-09-27 17:48:59 2140
PIL图片操作读取图片img=Image.open(“a.jpg”)显示图片im.show()#im是Image对象,im是numpy类型,通过Image.fromarray(nparr,mode='RGB')函数转换为Image对象图片的size(width,height)=img.size图片的模式mode=img.mode截区域img_c=img.crop(x1,y1,x2,y2)裁剪图片img=img.resize((size,size),Imag
系统 2019-09-27 17:48:58 2140
通常来说,Python的变量/数据类型非常多,但是它是不需要用户指定的,因为有些是根据部份系统函数生成,另外一些是自动根据变量的值识别的,这些数据类型常量在classtypes定义,所以使用时需要importtypes如:复制代码代码如下:importtypesa=[1,2,3]iftype(a)istypes.ListType:printaelse:print'notlist'Python的具体变量/数据类型如下:NoneTypeNone类型TypeTy
系统 2019-09-27 17:48:24 2140
类与类的关系依赖关系#依赖关系:将一个类的类名或者对象传给另一个类的方法中.classElephant:def__init__(self,name):self.name=namedefopen(self,r1):#print(ref1)print(f'{self.name}默念三声:芝麻开门')r1.open_door()defclose(self):print('大象默念三声:芝麻关门')classRefrigerator:def__init__(sel
系统 2019-09-27 17:48:13 2140
本文讲述一个用Python写的小程序,用于有注入点的链接,以检测当前数据库用户是否为sa,详细代码如下:#CodebyzhaoxiaobuEmail:little.bu@hotmail.com#-*-coding:UTF-8-*-fromsysimportexitfromurllibimporturlopenfromstringimportjoin,stripfromreimportsearchdefis_sqlable():sql1="%20and%20
系统 2019-09-27 17:47:32 2140
本人python新手,使用的环境是python2.7,勿喷复制代码代码如下:#-*-coding:utf8-*-importrandomimportstringimportsysreload(sys)sys.setdefaultencoding("utf8")defrandom_number():pwnumber=input("请输入需要密码个数:")pwlength=input("请输入需要密码长度:")ifpwlength<=10:foriinrang
系统 2019-09-27 17:47:14 2140
本文实例为大家分享了python实现日志按天分割的具体代码,供大家参考,具体内容如下日志格式:1.1.1.1--[30/Apr/2015:00:34:55+0800]“POST/iDataService/services/MemRoomServiceHTTP/1.0”200405“-”“Axis/1.4”“-”1.1.1.1--[30/Apr/2015:00:34:55+0800]“POST/iDataService/services/CutLoginSe
系统 2019-09-27 17:47:05 2140
本文实例为大家分享了python实现视频分帧的具体代码,供大家参考,具体内容如下importcv2vidcap=cv2.VideoCapture('005.avi')success,image=vidcap.read()count=0success=Truewhilesuccess:success,image=vidcap.read()cv2.imwrite("frame%d.jpg"%count,image)#saveframeasJPEGfileifc
系统 2019-09-27 17:46:48 2140