More explanation on __exit__ used in the video and how it returns the errors?Also what was the use of return True/False in the __exit__ method?

Can I get a bit more explanation about it? I am confused about the whole showing exceptions with the ‘With Block’

hey @Nitin-Bhattacharyya-2319140631658033 ,
firstly i am really sorry to be late on this response.
Now coming to your doubt.

Whenever we use with block in our code , it runs some pre defined functions , mainly __enter__ and __exit__ .

__enter__ function handles the task to be done on the particular object we are passing with the with block.

like in video , with A(5) as a: means on entering the with block , it will call the __enter__ function and return a self object of this class in a.

Now we can use a to get our task done.
Now once our task is completed , we want to end this with block and also release the memory we defined for this object, so to get this task done the with block calls __exit__ function .
This block gets arguments as errors or exceptions ( more specifically ) occurred while in the functioning of the with block.

and based on these exceptions we define what functioning do we need to provide to it, either we want to raise them or not. It depends upon you. But by default , it will raise those errors.
So , if we return True , it means that there was no error and the with block can easily exit the block.
but , if we return False , it means that there was some problem in the execution , may be an exception was caught and it requires to be raised to let the developer know about it.

I hope this helps. :slightly_smiling_face:.

Thanks really for the indepth explanation.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.