class MyOpener:

    def __init__(self, filename):
        print('Opening {}'.format(filename))

def close(self):
    print('Closing file.')

def write(self, text):
    print('Writing "{}"'.format(text))

def __enter__(self):
    return self

def __exit__(self, exc_type, exc_value, traceback):
    self.close()
How does open() work with and without `with`?