Por qué doesn `t este trabajo:problema con el con-declaración
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
me sale:
print z.var1
AttributeError: 'NoneType' object has no attribute 'var1'
Para obtener más información, consulte PEP 343 [enlace] (http://www.python.org/dev/peps/pep-0343/) que describe la sintaxis bastante bien – Voo