File Handling "r" - Read - It is default value. Opens a file for read only purpose, and raises an error if the file does not exist "a" - Append - Opens a file in append mode, if the file does not exist then it creates a new file with the same name. "w" - Write - Opens a file for write mode, if the file does not exist then it creates a new file with the same name. "x" - Create - Creates the specified file, if the file exists, then it returns an error.
File handling is one of the important part of any of the web application.
Python has many functions for creating, reading, updating, and deleting files.
File Handling
IN Python if you want to work with the files then the key function for that is open() function.
The open() function takes two parameters; filename, and mode.
There are four different methods (modes) for opening a file:
In addition you can also specify that if the file should be handled as binary or text mode. "t" - Text - Default value. Text mode "b" - Binary - Binary mode (e.g. images)
Syntax f = open("demofile.txt")
If you want to open a file in read only mode then it is enough to specify the name of the file.