Python的自列表的定义排序因是c++Acmer,故经常用到自定义排序第一种方法:对小于号进行重载因为所有比较都可通过小于号的结果进行推导classDch:def__init__(self,a,b):self.first=aself.second=bdef__str__(self):return"first={},second={}".format(self.first,self.second)def__lt__(self,other):if(self.
系统 2019-09-27 17:55:12 2207
说明:python环境搭建一共包含两部分--python解释器安装、python编辑器安装python解释器安装参考链接:Python3环境搭建python编辑器安装--pycharm参考链接:PyCharm安装教程(Windows)pip安装与使用参考链接:Pythonpip安装与使用--包含pip使用的常见命令注:在安装package时,如果提示pip非最新版本,且使用命令pipinstall-Upip不奏效,使用如下命令:pipinstall--us
系统 2019-09-27 17:53:56 2207
Python开发环境配置好了,但发现自带的代码编辑器貌似用着有点不大习惯啊,所以咱们就找一个“好用的”代码编辑器吧,网上搜了一下资料,Python常用的编辑器有如下一些:1.SublimeText2.Vim3.PyScripter4.PyCharm5.EclipsewithPyDev6.Emacs7.KomodoEdit8.Wing9.TheEricPythonIDE10.InteractiveEditorforPython11.ulipad12.Gean
系统 2019-09-27 17:53:43 2207
listlist是一种有序的集合,可以随时添加和删除其中的元素。跟java不一样的是可以使用arr[-1]0>-x>=-len(arr)索引的数字为0~len(arr)-1-len(arr)~-1超过会报错classmates=['A','B','C','D','E']print(classmates)print(len(classmates))foriinclassmates:print(i)'''['A','B','C','D','E']5ABCDE'
系统 2019-09-27 17:53:41 2207
转载:https://www.cnblogs.com/fujian-code/p/7501795.htmlPython列表具有内置的list.sort()方法,可以在原地修改列表。还有一个sorted()内置的函数从迭代构建一个新的排序列表。在本文中,我们将探讨使用Python排序数据的各种技术。转自http://mp.weixin.qq.com/s?__biz=MzI5NDY1MjQzNA==&mid=2247484360&idx=2&sn=5e0d78
系统 2019-09-27 17:53:24 2207
英文文档classmethod(function)Returnaclassmethodforfunction.Aclassmethodreceivestheclassasimplicitfirstargument,justlikeaninstancemethodreceivestheinstance.Todeclareaclassmethod,usethisidiom:classC:@classmethoddeff(cls,arg1,arg2,...):.
系统 2019-09-27 17:52:28 2207
一、安装PILPIL是PythonImagingLibrary简称,用于处理图片。PIL中已经有图片高斯模糊处理类,但有个bug(目前最新的1.1.7bug还存在),就是模糊半径写死的是2,不能设置。在源码ImageFilter.py的第160行:所以,我们在这里自己改一下就OK了。项目地址:http://www.pythonware.com/products/pil/二、修改后的代码代码如下:复制代码代码如下:#-*-coding:utf-8-*-fro
系统 2019-09-27 17:52:23 2207
学了下beautifulsoup后,做个个网络爬虫,爬取读者杂志并用reportlab制作成pdf..crawler.py复制代码代码如下:#!/usr/bin/envpython#coding=utf-8"""Author:AnemoneFilename:getmain.pyLastmodified:2015-02-1916:47E-mail:anemone@82flex.com"""importurllib2frombs4importBeautiful
系统 2019-09-27 17:51:35 2207
感觉这种理解有问题,举个例子来说。classDog(object):name='dog'definit(self):self.age=18d1=Dog()d2=Dog()这里有两个实例d1,d2吧。d1.name#输出dogd2.name#输出dogd1.name='abc'd1.name#输出abcd2.name#输出dogDog.name#输出dog原因是d1.name输出dog不是因为这个实例共享了类属性,而是因为这个实例没有dog属性,所以pyth
系统 2019-09-27 17:51:12 2207
压缩数据创建gzip文件先看一个略麻烦的做法importStringIO,gzipcontent='Lifeisshort.Iusepython'zbuf=StringIO.StringIO()zfile=gzip.GzipFile(mode='wb',compresslevel=9,fileobj=zbuf)zfile.write(content)zfile.close()但其实有个快捷的封装,不用用到StringIO模块f=gzip.open('fil
系统 2019-09-27 17:50:34 2207