Python Keylogger Tutorial - 3 - 'with' keyword in Python

preview_player
Показать описание
In the previous video we learned that whenever we use the open function it allocates some resources and memory to the file. And after we use the close function it releases the resources from the system. If we don't realease this memory it might give us some errors. So it's always a good practice to close the file.

Now this memory allocation and then it's release is used not only in file handling but in other kind of things as well. For example, listeners. We will be using these listeners to listen to keystrokes in future videos. But for now just understand that this listener also requires some memory allocation and then after the listener has done it's job we have to release the resources.

Now the function of the 'with' keyword is that it releases the memory automatically. So if use the 'with' keyword we won't have to type in the close function. So let's actually to that.

Now this might seem small of a change to you but when are writing a lot of code sometimes you might forget to release the resources. And this will create a lt of problems. Or if you are using something like listeners in which you don't really know when you are supposed to release the resources the 'with' keyword comes in pretty handy.

#python
Рекомендации по теме
Комментарии
Автор

You have made python programming easy yet fun😛.
Thanks so much

tumwesigyetomson
Автор

With keyword
F.write
Indentation error what is this ..?

puneetmishra