2020年4月20日
摘要: 自省/反射自省也称作反射,这个性质展示了某对象是如何在运行期取得自身信息的。如果传一个对象给你,你可以查出它有什么能力,这是一项强大的特性。如果Python不支持某种形式的自省功能,dir和type内建函数,将很难正常工作。还有那些特殊属性,像__dict__,__name__及__doc__cla 阅读全文
posted @ 2020-04-20 03:18 秋雨的蝴蝶 阅读(140) 评论(0) 推荐(0)
摘要: 动态导入:(通过字符串导入模块)module_t=__import__('m1.t') 直接定位到m1顶层模块名,t文件下test1方法print(module_t)module_t.t.test1()import importlibm=importlib.import_module('m1.t') 阅读全文
posted @ 2020-04-20 03:16 秋雨的蝴蝶 阅读(267) 评论(0) 推荐(0)
摘要: __setattr__,__delattr__,__getattr__class Foo: x=1 def __init__(self,y): self.y=y def __getattr__(self, item): print(' > from getattr:你找的属性不存在') def __ 阅读全文
posted @ 2020-04-20 03:15 秋雨的蝴蝶 阅读(168) 评论(0) 推荐(0)