上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 55 下一页
摘要: class SimplexNode: def __init__(self,value,post=None,prev=None): self.value=value self.post=post self.prev=prev def __repr__(self): # return 'Node: {} 阅读全文
posted @ 2020-10-05 02:53 ascertain 阅读(162) 评论(0) 推荐(0) 编辑
摘要: class Document: def __init__(self,content): self.t=content def print(self): print(self.t) class Pdf(Document):pass class PrintableMixin: def print(sel 阅读全文
posted @ 2020-10-04 14:57 ascertain 阅读(130) 评论(0) 推荐(0) 编辑
摘要: class Animal: __ORE= 'Animal ore' @classmethod def getore(cls): # 由于是私有属性,所以此处的cls.__ORE已经被解释器替换成cls._Animal_ORE print('class: {}\tclassORE: {}'.forma 阅读全文
posted @ 2020-10-04 14:24 ascertain 阅读(1394) 评论(0) 推荐(0) 编辑
摘要: import math class Shape: @property def area(self): raise NotImplementedError('Base class not implemented') class Triangle(Shape): def __init__(self, a 阅读全文
posted @ 2020-10-04 13:38 ascertain 阅读(260) 评论(0) 推荐(0) 编辑
摘要: class Oar: def __init__(self,oar): self.o=oar def print(self): print(self.o) # print 不会到class Oar下面找,除非引用self.print def decorator(cls): def _print(sel 阅读全文
posted @ 2020-10-04 13:36 ascertain 阅读(385) 评论(0) 推荐(0) 编辑
摘要: def printable(): def wrapper(cls): cls.print=lambda self:print(self.content) return cls return wrapper @printable() # 先调用生成wrapper Word=wrapper(Word) 阅读全文
posted @ 2020-10-03 21:39 ascertain 阅读(203) 评论(0) 推荐(0) 编辑
摘要: OCP原则:多继承,少修改 继承的用途:增强基类,实现多态 多态 在面向对象中,父类和子类通过继承联系在一起,如果可以通过一套方法,就可以实现不同表现,就是多态 一个类继承自多个类就是多继承,他将具有多个类的特征 class Document: def __init__(self,content): 阅读全文
posted @ 2020-10-03 18:56 ascertain 阅读(342) 评论(0) 推荐(0) 编辑
摘要: class A: def __init__(self,a): self.a=a class B(A): def __init__(self,b,c): self.b=b self.c=c def printv(self): print(self.b) print(self.a) f=B(200,30 阅读全文
posted @ 2020-10-03 18:00 ascertain 阅读(189) 评论(0) 推荐(0) 编辑
摘要: class Animal: x=123 def __init__(self,name): self._name=name self.__age=10 @property def name(self): return self._name def shout(self): print('Animal 阅读全文
posted @ 2020-10-03 13:14 ascertain 阅读(252) 评论(0) 推荐(0) 编辑
摘要: class Car: def __init__(self,brand,speed,color,price): self.b=brand self.s=speed self.c=color self.p=price def __repr__(self): return '''\ brand:%s sp 阅读全文
posted @ 2020-10-03 01:34 ascertain 阅读(127) 评论(0) 推荐(0) 编辑
摘要: import random class RandomGenerator: def __init__(self,count=10,minimum=1,maximum=100): self.count=count self.min=minimum self.max=maximum self.g=self 阅读全文
posted @ 2020-10-02 23:12 ascertain 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 在其他面向对象的高级语言中,都有重载的概念 重载: 同一个方法名,但是参数的数量和类型不一样,就是同一个方法的重载 Python没有重载 Python不需要重载 Python中,方法(函数)定义中,形参非常灵活,不需要指定类型(就是指定了,也只是一个说明,而非约束),参数个数也不固定(可变参数),一 阅读全文
posted @ 2020-10-02 21:56 ascertain 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 类中可以定义__del__方法,称为析构方法 作用: 销毁类的实例时调用,以释放占用的资源 由于python实现了垃圾回收机制,这个方法不确定何时执行,有必要时,使用del语句手动删除实例 class Person: def __init__(self,name,age=20): self.name 阅读全文
posted @ 2020-10-02 19:06 ascertain 阅读(167) 评论(0) 推荐(0) 编辑
摘要: property装饰器: 后面跟的函数名就是以后的属性,它即是getter,这个必须有,只读属性 setter装饰器: 于属性名同名,接收两个参数,第一个是self,第二个是将要赋值的值,将属性变为可写 deleter装饰器: 可以控制属性是否删除 property装饰器必须在前,setter,de 阅读全文
posted @ 2020-10-02 18:55 ascertain 阅读(808) 评论(0) 推荐(0) 编辑
摘要: lambda <args>:<expression> <expression>必须是单个表达式,不能是多个由;分割的表达式 使用exec函数 b=1 p=lambda v:exec("global b;b+=1;print(v+b)") print(p(1)) print(p(2)) 此种方式返回值 阅读全文
posted @ 2020-10-02 18:08 ascertain 阅读(3379) 评论(0) 推荐(0) 编辑
摘要: relevance.py from relevance1 import Mim from relevance2 import get p=Mim(22,33,44) print(p.get()) def monkeypath4Mim(): Mim.get=get if __name__ == '__ 阅读全文
posted @ 2020-10-02 13:10 ascertain 阅读(108) 评论(0) 推荐(0) 编辑
摘要: from pathlib import Path def openfile(path:str)->None: yield path def cix(path:str): p=Path(path) if p.exists(): if p.is_file(): yield from openfile(s 阅读全文
posted @ 2020-10-02 12:50 ascertain 阅读(190) 评论(0) 推荐(0) 编辑
摘要: from pathlib import Path import argparse,sys,datetime,stat,platform def showdir(path:str='.',all=False,detail=False,human=False,reverse=False): def co 阅读全文
posted @ 2020-10-02 11:25 ascertain 阅读(224) 评论(0) 推荐(0) 编辑
摘要: class Mse: @classmethod def __new__(cls,*args,**kwargs): pass @classmethod def class_method(cls): print('class={0.__name__} ({0})'.format(cls)) cls.HE 阅读全文
posted @ 2020-10-02 11:22 ascertain 阅读(131) 评论(0) 推荐(0) 编辑
摘要: import re,datetime,threading,queue from pathlib import Path from user_agents import parse from collections import defaultdict log='''10.1.1.95 - e800 阅读全文
posted @ 2020-10-01 19:00 ascertain 阅读(246) 评论(0) 推荐(0) 编辑
上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 55 下一页