I am running pylint for bug detection in my project and stumble on this warning. How can I fix this warning?
suppose you are opening a file:
file_handle = open("some_file.txt", "r")
...
...
file_handle.close()
You need to close that file manually after required task is done. If it's not closed, then resource (memory/buffer in this case) is wasted.
If you use with
in above example:
with open("some_file.txt", "r") as file_handle:
...
...
there is no need to close that file. Resource de-allocation automatically happens when you use with
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With