Member-only story
How to Read and Write a File in Python ?
A quick guide to file operations in python
3 min readMay 2, 2022
Open/ Close
The syntax for opening a file operation is :
There are two operations associated with file. We use open to create a file descriptor. Then we have to close the file to prevent memory leakage.
But closing the file manually is tedious process. And prone to error.
In the above example the file is opened but never closed. Because once the exception happens, the program will exit.