In this post we will be making a context manager using Python. Context managers comes in handy when we are using the
with statement in Python. We will be making a context manager for writing HDFS file in Pandas. This will be a continuation of my previous post, regarding HDFS using Python Pandas.
We will start be creating a class for our context manager:
__exit__ are the magic functions of
__enter__ is called immediately after the
__init__ function and
__exit__ is called at the end of the
Now lets use our context manager class:
This will be our entire code:
This can be also used with opening databases, files, and a lot more.
Happy coding !!!