File handling is an important part of any web application. These include creating, writing, reading and deleting a file.
In python, we don’t have to import any library or package for creating a file. We have inbuilt function to do this.
The key function for working with files in python is the open() funtion.
There are different modes for opening file:-
- Read mode – r- This mode is used to read the file
- Write mode- w- This mode is used to write the file
- Read and write mode- w+ – This mode is used to both read and write a file.
- Append mode- a – This mode is used to append the file
Creating a file:-
For creating a file we have to first open it and write in it.
object=open("name of file", w+)
In this way we can create a file and read and write a file in python.