摘要: 1.元类(Metaclass) 元类是用于创建类的类。它定义了类的创建行为,可以控制类的属性、方法的创建和修改。 1.日志记录:在创建类时自动添加日志记录相关的方法。 class LoggingMeta(type): def __new__(cls, name, bases, attrs): def 阅读全文
posted @ 2024-12-11 10:39 zwx901323 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 1.__slots__控制属性访问 class MyClass: __slots__ = ('attr1', 'attr2') def __init__(self): self.attr1 = 10 self.attr2 = 20 # 尝试添加不在 __slots__ 中的属性会报错 obj = M 阅读全文
posted @ 2024-12-11 10:05 zwx901323 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 抽象定义 阅读全文
posted @ 2024-12-11 09:43 zwx901323 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 多态定义 阅读全文
posted @ 2024-12-11 09:43 zwx901323 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 继承定义 阅读全文
posted @ 2024-12-11 09:43 zwx901323 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 封装定义 阅读全文
posted @ 2024-12-11 09:43 zwx901323 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 1.创建无限循环迭代对象:count,cycle,repeat from itertools import count for i in count(1, 2): if i > 10: break print(i) # 以1开始,2为步长,无限range结果:1 3 5 7 9 from itert 阅读全文
posted @ 2024-12-02 17:09 zwx901323 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 1.创建一个简单的hello文件,里面只有一个类A,A属性为name 2.获取文件下面的未知类有哪些? 当只知道需要导入的类名称,但是不知道具体位置,如何动态导入? import importlib.util import inspect # 文件夹下面有个脚本,下面只有一个类: from test 阅读全文
posted @ 2023-07-25 21:54 zwx901323 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 测试程序的执行时间 from timeit import timeit def hello(): for i in range(10000): pass res = timeit("hello()", "from __main__ import hello", number=100) print(r 阅读全文
posted @ 2023-05-09 21:29 zwx901323 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 放弃append,推荐concat df.append([1,2,3]) def pandas_append(data_list, df): if isinstance(data_list, list): new_data = {key:[data_list[num]] for num, key i 阅读全文
posted @ 2023-03-13 22:01 zwx901323 阅读(223) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示