3.1 Introduction To Files
3.1 Introduction To Files
Python has several functions for creating, reading, updating, and deleting files.
Plays an important role when the data needs to be stored permanently into the file.
A file is a named location on disk to store related information. We can access the stored information (non
volatile) after the program termination.
A file is the collection of data stored on a disk in one unit identified by filename.
⮚ Text File
⮚ Binary File
⮚ Open a file
OPENING A FILE
open() function that accepts two arguments, file name and access mode in which the file is accessed.
SYNTAX
There are four different methods (access modes) for opening a file:
"r" - Read - Default value. Opens a file for reading, error if the file does not exist
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
"x" - Create - Creates the specified file, returns an error if the file exists