为什么这不起作用:
class X:
var1 = 1
def __enter__(self): pass
def __exit__(self, type, value, traceback): pass
with X() as z:
print z.var1
Run Code Online (Sandbox Code Playgroud)
我明白了:
print z.var1
AttributeError: 'NoneType' object has no attribute 'var1'
Run Code Online (Sandbox Code Playgroud)