摘要: 示例: class Foo: def __enter__(self): print("Foo: __enter__") def __exit__(self, exc_type, exc_val, exc_tb): print("Foo: __exit__") foo = Foo() with foo 阅读全文
posted @ 2020-05-09 01:40 静静别跑 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 1. __call__() 方法 对象+() 可以直接调用__call__()方法 , 类似普通函数的调用 class CallTest(object): def __init__(self): print('I am __init__') def __call__(self): print('I 阅读全文
posted @ 2020-05-09 01:36 静静别跑 阅读(1847) 评论(0) 推荐(0) 编辑