From a3ac746ea2bb58c773c2d55d135a9280ac02377f Mon Sep 17 00:00:00 2001 From: Jared McKnight Date: Mon, 17 Jan 2022 11:59:08 -0500 Subject: [PATCH] enable use of with syntax --- ft4222/ft4222.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ft4222/ft4222.pyx b/ft4222/ft4222.pyx index fc14dff..00bca8d 100644 --- a/ft4222/ft4222.pyx +++ b/ft4222/ft4222.pyx @@ -181,6 +181,12 @@ cdef class FT4222: FT4222_UnInitialize(self._handle) FT_Close(self._handle) + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + def close(self): """Closes the device.""" status = FT4222_UnInitialize(self._handle)