# 玩with语句class TestWith(object): def __init__(self): print("this is init of TestWith") def if_exist(self): print("I'm here") def __enter__(self): print("This is TestWith __enter__") return self def __exit__(self, *args): for i in args: print(i) print("Now __exit__")with TestWith() as t: t.if_exist()