摘要:
form m1 import t t.test() #如果导入的t是字符串怎么办 解决办法: 1.0 m=__impotr__("m1.t") print(m) #<module 'm1' (namespace)> 只能获取顶级模块 即m1 m.t.test() 所以要这么调用 2.0 import 阅读全文
posted @ 2020-07-11 18:32
彡心如止水彡
阅读(132)
评论(0)
推荐(0)
摘要:
classmethod class Classmethod: def __init__(self,func): self.func=func def __get__(self, instance, owner): def test(*args,**kwargs): return self.func( 阅读全文
posted @ 2020-07-11 18:22
彡心如止水彡
阅读(164)
评论(0)
推荐(0)
摘要:
1.使用描述符+类的装饰器 class Typed: def __init__(self,key,type): self.key=key self.type=type def __get__(self, instance, owner): return instance.__dict__[self. 阅读全文
posted @ 2020-07-11 16:36
彡心如止水彡
阅读(649)
评论(0)
推荐(0)
摘要:
class Room: def __init__(self,name,length,width): self.name=name self.length=length self.width=width @property def test(self): return self.length*self 阅读全文
posted @ 2020-07-11 15:23
彡心如止水彡
阅读(137)
评论(0)
推荐(0)
摘要:
所有类都是元类的对象 class Foo: pass print(type(Foo)) #<class 'type'> 定义类的2种方式: 1. 第一种就是正常的用class来定义 2. Foo=type("Foo",(object,),{"x":1}) type的三个参数: 1.类名 2.继承的类 阅读全文
posted @ 2020-07-11 14:59
彡心如止水彡
阅读(121)
评论(0)
推荐(0)
摘要:
isinstance与issubclass的使用 class Foo: pass f=Foo() print(isinstance(f,Foo)) #判断f是否是Foo的实例 class Coo: pass print(issubclass(Coo,Foo)) #判断Coo是否是Foo的子类 c=C 阅读全文
posted @ 2020-07-11 00:12
彡心如止水彡
阅读(102)
评论(0)
推荐(0)

浙公网安备 33010602011771号