class Foo(object):

    def __enter__(self):
        print('In __enter__')
return Bar()

def __exit__(self, typ, val, traceback):
    print('In __exit__')


class Bar(object):

    def func1(self):
        print('In func1')

def func2(self):
    print('In func2')
Writing a Python class that can only be used as a context manager