爲什麼不`噸這項工作:問題使用with語句
class X:
var1 = 1
def __enter__(self): pass
def __exit__(self, type, value, traceback): pass
class Y:
x = X()
y = Y()
with y.x as z:
print z.var1
我得到:
print z.var1
AttributeError: 'NoneType' object has no attribute 'var1'
欲瞭解更多信息,請參閱PEP 343 [鏈接](http://www.python.org/dev/peps/pep-0343/),它很好地描述了語法 – Voo 2011-02-23 16:05:57