Change the definition of X
to
class X(object):
var1 = 1
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
pass
with
assigns the return value of the __enter__()
method to the name after as
. Your __enter__()
returned None
, which was assigned to z
.
I also changed the class to a new-style class (which is not critical to make it work).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…