摘要: 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)
摘要: import redef mul_div(exp): while re.search("[+-]{2,}",exp): exp = exp.replace("--", "+") exp = exp.replace("-+", "-") exp = exp.replace("++", "+") exp 阅读全文
posted @ 2020-07-08 22:20 彡心如止水彡 阅读(189) 评论(0) 推荐(0)
摘要: JDialog(Frame owner, String title, boolean modal) owner代表对话框所依赖的窗口 title表示标题 modal表示是否强制 阅读全文
posted @ 2020-04-30 13:44 彡心如止水彡 阅读(407) 评论(0) 推荐(0)
摘要: 正常思路 f=open('test.txt','br') s=f.readlines() print(s[-1].decode()) 这种思路,如果文件过大则处理过慢,暂用内存太多 优化思路 with open('test.txt','rb') as f: book = -10 #设置偏移量大概估算 阅读全文
posted @ 2020-04-01 15:26 彡心如止水彡 阅读(281) 评论(0) 推荐(0)
摘要: 小明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性他先用计算机生成了N个1~1000之间的随机整数(N<=1000),N是用户输入的,对于其中重复的数字,只保留一个,把其余相同的数字去掉,不同的数对应着不同的学生的学号,然后再把这些数从小到大排序,按照排好的顺序去找同学做调查,请你协助明明 阅读全文
posted @ 2020-03-08 19:13 彡心如止水彡 阅读(400) 评论(0) 推荐(0)