class Meter:

    def __init__(self, dev):
        self.dev = dev

def __enter__(self):
    self.fd = open(self.dev, MODE)
return self.fd

def __exit__(self, type, value, traceback):
    close(self.fd)
meter = Meter('dev/tty0')
with meter as m:
    m.read()
Implementing use of 'with object() as f' in custom class in python