HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

Python File Handling


File handling provides a mechanism to store the output of a program in a file and to perform various operations on it. File handling in Python allows you to perform a wide range of operations, such as creating, reading, writing, appending, renaming, and deleting files.


Advantages of File Handling:


Disadvantages of File Handling:


Mode of File Handling:


Mode Description
r Open an existing file for a read operation.
w Open an existing file for a write operation.If the file already contains some data,then it will be overridden but if the file is not present then it creates the file as well.
a Open an existing file for append operation.It won’t override existing data.
r+ To read and write data into the file.The previous data in the file will be overridden.
w+ To write and read data.It will override existing data.
a+ To append and read data from the file.It won’t override existing data.