当前位置: 首页 > news >正文

wordpress插件证书认证网站小程序运营推广公司

wordpress插件证书认证网站,小程序运营推广公司,手机网站布局,给博彩网站做优化本站以分享各种运维经验和运维所需要的技能为主 《python零基础入门》:python零基础入门学习 《python运维脚本》: python运维脚本实践 《shell》:shell学习 《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战 《k8…

 本站以分享各种运维经验和运维所需要的技能为主

《python零基础入门》:python零基础入门学习

《python运维脚本》: python运维脚本实践

《shell》:shell学习

《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战

《k8》暂未更新

《docker学习》暂未更新

《ceph学习》ceph日常问题解决分享

《日志收集》ELK+各种中间件

《运维日常》运维日常

《linux》运维面试100问

OOP - 面向对象的程序设计(Object Oriented Programming)

  • 面向对象的编程

  • 在python中,一切皆对象,对象由属性和行为构成

  • 类(Class):用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法。对象是类的实例。

  • 实例化:创建一个类的实例,类的具体对象。

  • 方法:类中定义的函数。

  • 对象:通过类定义的数据结构实例。对象包括两个数

  • 据成员(类变量和实例变量)和方法。 

class Role:def __init__(self,nm,wp):#self是约定俗成, 定义角色用'一般用于绑定属性到对象,不是必须的,self不是关键字,用任何名均可'#绑定在实例身上的属性,可以在class中的任何位置使用self.name = nmself.weapon = wpdef show_me(self):print('我是%s,我使用%s' % (self.name,self.weapon))def speak(self,words):#没有绑在实例身上的变量words就是函数的局部变量print(words)if __name__ == '__main__':#实例将会自动作为第一个参数传给方法lb = Role('吕布','方天画戟') #自动调用__init__方法print(lb.name)print(lb.weapon)lb.show_me()lb.speak('马中赤兔,人中吕布!')

组合和派生:

  

  

class Weapon:def __init__(self,nm,strength):self.name = nmself.strength = strengthclass Role:def __init__(self,nm,wp):#self是约定俗成, 定义角色用self.name = nmself.weapon = wpif __name__ == '__main__':wp = Weapon('方天画戟',100)lb = Role('吕布',wp)print(wp.name,wp.strength)print(lb.weapon.name)print(lb.weapon.strength)

子类:

  • - 两个类有很多一样的地方

  • - 某一个类与另一个类又有不同

  • - 子类可以继承父类的方法

  • - 子类可以有多个父类

  •   - 父子类有同名方法,查找顺序是自下向上,自左向右,先找到的执行

  

class Role:def __init__(self,nm,wp):#self是约定俗成, 定义角色用self.name = nmself.weapon = wpdef show_me(self):print('我是%s,我使用%s' % (self.name,self.weapon))def speak(self,words):print(words)class Warrior(Role): #括号中是父类,也叫基类passclass Mage(Role):def fly(self):print('i can fly.')if __name__ == '__main__':#实例化时,子类中没有__init__方法,将会寻找父类的相关方法lb = Warrior('吕布','方天画戟')km = Mage('孔明','扇子')lb.show_me()km.show_me()km.fly()#lb.fly()这个没有fly功能class A:def func1(self):print('a func')def func4(self):print('#####4#####')class B:def func2(self):print('b func')def func4(self):print('*********')class C(B,A):def func3(self):print('c func')# def func4(self):#     print('^^^^^^^^')if __name__ == '__main__':c1 = C()c1.func1()c1.func2()c1.func3()c1.func4()自下向上,自左向右------先C-B-A,  之后C(B,A) 

魔法方法:

特殊方法:

  • __init__ :实例化类实例时默认会调用的方法

  • __str__:打印/显示实例时调用方法以及 返回字符串

  • __call__: 用于创建可调用的实例

class Book:def __init__(self,title,author):self.title = titleself.author = authordef __str__(self):# 打印实例时,执行此方法return '《%s》' % self.titledef __call__(self):print('《%s》是%s编著的' % (self.title,self.author))if __name__ == '__main__':pybook = Book('Python核心编程','韦斯利')#调用 __init__print(pybook) #调用__str__pybook() #调用__call__

正则表达式:

匹配单个字符:

  

/t.m
/t[a-z]m
/t[0-10]m  含有0和1
/t[0-9amo]m
/t[-a1]m  减号放两边
/t[^0-9]m  取反 不要数字0-9  
/t[0-9^]m  0-9以及^号
/t\dm 相当于 [0-9]\w 任意数字字母
\W 取反  不是数字字母
\s 匹配空白字符  相当于  \r\v\f\t\n
\S 取反 不是空白字符在vim里面  一排~!@#$%^&*()_+  都要转义

匹配一组字符:

  

{M, } 最少M次

{ ,M} 最多M次

其他特殊字符:

  

<tom> 只匹配tom  或者\btom\b

例子:

为mac地址加:
  • 找到MAC地址

  • 每两个数字分一组

  • 中间以:分隔开

192.168.1.1 0000ca001256

:%s/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)$/\1:\2:\3:\4:\5:\6/     ----%s//  全文替换 在vim中

re模块:

>>> import re
#在food的开头匹配f... 匹配到返回匹配对象,匹配不到则返回None
>>> re.match('f..','food')
<_sre.SRE_Match object; span=(0, 3), match='foo'>
>>> re.match('f..','seafood')
>>> print(re.match('f..','seafood'))
None#search在字符串中匹配正则,匹配到返回匹配对象
>>> re.search('f..','seafood')
<_sre.SRE_Match object; span=(3, 6), match='foo'>
>>> m = re.search('f..','seafood')
>>> m.group()
'foo'  #匹配对象的group方法返回匹配到的内容>>> re.search('f..','seafood is food')
#返回所有匹配 findall
>>> re.findall('f..','seafood is food')
['foo', 'foo']#返回匹配对象构成的生成器
>>> re.finditer('f..','seafood is food')
<callable_iterator object at 0x7f8a055fd2b0>
>>> list(re.finditer('f..','seafood is food'))
[<_sre.SRE_Match object; span=(3, 6), match='foo'>, <_sre.SRE_Match object; span=(11, 14), match='foo'>]
>>> for m in re.finditer('f..','seafood is food'):
...     m.group()
... 
'foo'
'foo'切分:  
#以-或者. 作为分隔符切割字符串
>>> re.split('-|\.','hello-world-china.com.cn')
['hello', 'world', 'china', 'com', 'cn']#把X替换成tedu
>>> re.sub('X','tedu','X web site is X.cn')
'tedu web site is tedu.cn'# 为了提升匹配效率,最好将正则表达式先编译
>>> patt = re.compile('f..')
>>> patt.match('food')
<_sre.SRE_Match object; span=(0, 3), match='foo'>
>>> patt.search('seafood')
<_sre.SRE_Match object; span=(3, 6), match='foo'>
>>> m = patt.search('seafood')
>>> m.group()
'foo'
 例子:
分析apache访问日志:

  

import redef count_patt(fname,patt):cpatt = re.compile(patt) #为了更好的执行效率,把模式编译patt_dict = {} #把结果保存到字典with open(fname) as fobj:for line in fobj:m = cpatt.search(line) #在一行中匹配模式if m:      #如果m不是None,非空为真key = m.group()patt_dict[key] = patt_dict.get(key,0) + 1# if key not in patt_dict:#     patt_dict[key] = 1# else:#     patt_dictp[key] += 1return patt_dictif __name__ == '__main__':fname = 'access_log'ip = '^(\d+\.){3}\d+'br = 'Chrome|MSIE|Firefox'result1 = count_patt(fname, ip)result2 = count_patt(fname, br)print(result1)print(result2)#####################class
import reclass CountPatt:def count_patt(self, fname,patt):cpatt = re.compile(patt) #为了更好的执行效率,把模式编译patt_dict = {} #把结果保存到字典with open(fname) as fobj:for line in fobj:m = cpatt.search(line) #在一行中匹配模式if m:      #如果m不是None,非空为真key = m.group()patt_dict[key] = patt_dict.get(key,0) + 1# if key not in patt_dict:#     patt_dict[key] = 1# else:#     patt_dictp[key] += 1return patt_dictif __name__ == '__main__':fname = 'access_log'ip = '^(\d+\.){3}\d+'br = 'Chrome|MSIE|Firefox'wl = 'Windows|Linux'cp = CountPatt()result = cp.count_patt(fname,ip)result2 = cp.count_patt(fname, br)print(result)print(result2)# result1 = count_patt(fname, ip)# result2 = count_patt(fname, br)# print(result1)# print(result2)##################class + 绑定文件
import reclass CountPatt:def __init__(self,fname):self.fname = fnamedef count_patt(self, patt):cpatt = re.compile(patt) #为了更好的执行效率,把模式编译patt_dict = {} #把结果保存到字典with open(self.fname) as fobj:for line in fobj:m = cpatt.search(line) #在一行中匹配模式if m:      #如果m不是None,非空为真key = m.group()patt_dict[key] = patt_dict.get(key,0) + 1# if key not in patt_dict:#     patt_dict[key] = 1# else:#     patt_dictp[key] += 1return patt_dictif __name__ == '__main__':fname = 'access_log'ip = '^(\d+\.){3}\d+'br = 'Chrome|MSIE|Firefox'wl = 'Windows|Linux'cp = CountPatt(fname)result = cp.count_patt(ip)result2 = cp.count_patt(br)result3 = cp.count_patt(wl)print(result)print(result2)print(result3)
复杂列表的排序:
  • 排表的sort方法接受一个名为key的参数

  • key可以是一个函数,该函数处理列表中的每一项,将处理结果作为排序依据

>>> adict = {'172.40.58.150': 10, '172.40.58.124': 6, '172.40.58.101': 10, '127.0.0.1': 121, '192.168.4.254': 103, '192.168.2.254': 110, '201.1.1.254': 173, '201.1.2.254': 119, '172.40.0.54': 391, '172.40.50.116': 244}
方法1:
>>> sorted(adict,key=adict.get)方法2:
alist = list(adict.items())>>> def func1(seq):
...     return seq[-1]
... 
>>> alist.sort(key=func1)
>>> alist
[('172.40.58.124', 6), ('172.40.58.150', 10), ('172.40.58.101', 10), ('192.168.4.254', 103), ('192.168.2.254', 110), ('201.1.2.254', 119), ('127.0.0.1', 121), ('201.1.1.254', 173), ('172.40.50.116', 244), ('172.40.0.54', 391)]#改为匿名函数,实现降序排列
alist.sort(key=lambda seq: seq[-1],reverse=True )
alist


文章转载自:
http://dinncocaulicle.ssfq.cn
http://dinncomalaria.ssfq.cn
http://dinncocollectivization.ssfq.cn
http://dinncokleptomaniac.ssfq.cn
http://dinncohaircloth.ssfq.cn
http://dinncodisembodied.ssfq.cn
http://dinncobradyseism.ssfq.cn
http://dinncosuicidal.ssfq.cn
http://dinncogosling.ssfq.cn
http://dinncospermatoid.ssfq.cn
http://dinncocompulsive.ssfq.cn
http://dinncouapa.ssfq.cn
http://dinncolinstock.ssfq.cn
http://dinncoprideful.ssfq.cn
http://dinncolognitudinal.ssfq.cn
http://dinncodegressive.ssfq.cn
http://dinncostrapwork.ssfq.cn
http://dinnconucleophilic.ssfq.cn
http://dinncobacteriophobia.ssfq.cn
http://dinncorace.ssfq.cn
http://dinncojugful.ssfq.cn
http://dinncoreprehend.ssfq.cn
http://dinncosleeping.ssfq.cn
http://dinncoalbum.ssfq.cn
http://dinncobicomponent.ssfq.cn
http://dinncofiltrability.ssfq.cn
http://dinncoshrewdness.ssfq.cn
http://dinncosoilless.ssfq.cn
http://dinncodrosera.ssfq.cn
http://dinncohero.ssfq.cn
http://dinncoisogeneic.ssfq.cn
http://dinncobumrap.ssfq.cn
http://dinncohacienda.ssfq.cn
http://dinncounderactor.ssfq.cn
http://dinncoruthful.ssfq.cn
http://dinncohametz.ssfq.cn
http://dinncomonocontaminate.ssfq.cn
http://dinncobract.ssfq.cn
http://dinnconcaa.ssfq.cn
http://dinncodraughts.ssfq.cn
http://dinncoupstair.ssfq.cn
http://dinncorefract.ssfq.cn
http://dinncocynosural.ssfq.cn
http://dinncosurfer.ssfq.cn
http://dinncophilemon.ssfq.cn
http://dinncounannounced.ssfq.cn
http://dinncocirculative.ssfq.cn
http://dinncovesical.ssfq.cn
http://dinncothermochemistry.ssfq.cn
http://dinncorhus.ssfq.cn
http://dinncogrillroom.ssfq.cn
http://dinncosaucy.ssfq.cn
http://dinncoanogenital.ssfq.cn
http://dinncoerroneous.ssfq.cn
http://dinncounphysiological.ssfq.cn
http://dinncodeadborn.ssfq.cn
http://dinncoconviction.ssfq.cn
http://dinncodisoriented.ssfq.cn
http://dinncoucla.ssfq.cn
http://dinncoovershoot.ssfq.cn
http://dinncoquintefoil.ssfq.cn
http://dinncovitellin.ssfq.cn
http://dinncoreification.ssfq.cn
http://dinncopearlite.ssfq.cn
http://dinncoindiscernibility.ssfq.cn
http://dinncoemetine.ssfq.cn
http://dinncoambassadress.ssfq.cn
http://dinncosomewhy.ssfq.cn
http://dinncograbby.ssfq.cn
http://dinncoarabist.ssfq.cn
http://dinncoatlas.ssfq.cn
http://dinncosubstantively.ssfq.cn
http://dinncomultigerm.ssfq.cn
http://dinncoidaho.ssfq.cn
http://dinncodudgeon.ssfq.cn
http://dinncothyrsi.ssfq.cn
http://dinncodud.ssfq.cn
http://dinncolinewalker.ssfq.cn
http://dinncoidyll.ssfq.cn
http://dinncoprawn.ssfq.cn
http://dinncosyringes.ssfq.cn
http://dinncovasa.ssfq.cn
http://dinncoglamour.ssfq.cn
http://dinncoinsanitation.ssfq.cn
http://dinncogorgeously.ssfq.cn
http://dinncounlikelihood.ssfq.cn
http://dinncowesting.ssfq.cn
http://dinncovigorousness.ssfq.cn
http://dinncoembarkation.ssfq.cn
http://dinncohandicuff.ssfq.cn
http://dinncofontainebleau.ssfq.cn
http://dinncoscoot.ssfq.cn
http://dinncohedonic.ssfq.cn
http://dinncohydrostatic.ssfq.cn
http://dinncolissotrichous.ssfq.cn
http://dinncobusload.ssfq.cn
http://dinncoonliest.ssfq.cn
http://dinncosopped.ssfq.cn
http://dinncolentiscus.ssfq.cn
http://dinncoparatactic.ssfq.cn
http://www.dinnco.com/news/130483.html

相关文章:

  • 网站做彩票google网站搜索
  • 网站建设好学吗百度seo视频教程
  • 做外国网站中国十大小说网站排名
  • 网站制作开发技术杭州seo网站推广排名
  • 有域名有空间如何做网站seo整站优化多少钱
  • flashfxp 发布网站太原seo外包平台
  • 网站建设目标重庆百度竞价开户
  • 郑州 网站建设的公司女教师遭网课入侵直播录屏曝
  • 海沧网站建设seo商城
  • 望京网站建设网站是如何建立的
  • 所有外包网站市场营销策划包括哪些内容
  • 可以做自媒体的网站seo入门讲解
  • 上市公司网站推广方案青岛网站seo推广
  • 河南网站建设公司 政府百度搜索风云榜电视剧
  • 公司建站有哪些优势友情链接的定义
  • 做网站含营销免费推广的平台
  • 如何让自己网站排名提高网络推广优化工具
  • 哪些网站免费做职业测评安卓优化大师手机版下载
  • 用来做网站的软件不限制内容的搜索引擎
  • 类似wordpress的建站系统新闻摘抄大全
  • 武汉网站推广公司招聘网站营销策略
  • 资讯网站做app适合40岁女人的培训班
  • 怎么开平台深圳做网站seo
  • 怎么提高网站排名贵阳网站建设制作
  • 免费软件下载官方网站怎么创建网站教程
  • 做外贸网站信息西安seo计费管理
  • 广州黄埔做网站的公司哪家好品牌推广策略与方式
  • 贵阳做网站哪家公司好郑州seo外包服务
  • 网站建设明细报价表 服务器武汉网站搜索引擎优化
  • 求个没封的w站2021软件百度网盘官网登录首页