摘要: 1.__getattr__:当调用对象属性不存在时,才会触发 2.__delattr__:删除时会触发 3.__setattr__:设置属性时就会触发 阅读全文
posted @ 2019-03-26 18:36 wind_y 阅读(183) 评论(0) 推荐(0) 编辑
摘要: module_t=__import__('m1.t') #可以执行t,但拿到的是顶层的模块 print(module_t) # module_t.t.test1() # from m1.t import * # from m1.t import test1,_test2 # # test1() # _test2() import importlib m=importlib.im... 阅读全文
posted @ 2019-03-26 16:42 wind_y 阅读(92) 评论(0) 推荐(0) 编辑
摘要: 反射的应用场景: 当是两个人写代码时,不需要必须一个人先写完 可以实现定义好接口,接口只有在被完成时才会真正执行,这实现了即插即用,‘后期绑定’, 即可以只定义接口,后期再去实现接口的功能 阅读全文
posted @ 2019-03-26 15:39 wind_y 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 约定一:任何以单下划线开头的名字都应该是内部的,私有的 python并不会真的阻止你访问私有的属性,print(p1._star)依然是可以的 模块也遵循这种约定,如果模块名以单下划线开头,那么from module import时不能被导 入, 但是from module import _priv 阅读全文
posted @ 2019-03-26 10:59 wind_y 阅读(123) 评论(0) 推荐(0) 编辑