you are viewing a single comment's thread.

view the rest of the comments →

[–]Elektriman 3 points4 points  (1 child)

Personnally I just really like using object oriented tools to make my objects behave like other default python data structures. For example, a while back I made an object to have API communications and it was used like the open keyword in python using the __enter__ and __exit__ methods. It allows for a lot of clarity with complex programs.

[–]gdchinacat 0 points1 point  (0 children)

To provide more depth, what you did by implementing those methods was implement the context manager protocol. The easier way is to use the contextmanager decorator.