我一直在尝试将contextlib
与Python一起使用...但它返回错误...代码是
from contextlib import contextmanager
import contextlib
class Mgr():
def __enter__(self):
return self
def __exit__(self, ext, exv, trb):
if ext is not None: print "no not possible"
print "OK I caught you"
return True
@contextlib.contextmanager
def honey(self):
print 'guli'
with contextmanager() as d:
print d
当我运行此代码时,它有像我这样的错误
TypeError: contextmanager() takes exactly 1 argument (0 given)
代码在没有contextlib
的情况下正常工作。但我需要使用contextlib
..
如何使用honey
调用contextmanager
函数?..