File Handling
File Handling
• File handling refers to the process of performing operations on a
file such as creating, opening, reading, writing and closing it,
through a programming interface. It involves managing the data
flow between the program and the file system on the storage
device, ensuring that data is handled safely and efficiently.
• File handling in Python involves interacting with files on your
computer to read data from them or write data to them. Python
provides several built-in functions and methods for creating,
opening, reading, writing, and closing files.
Conti…
• File : File is nothing but name of memory location on disk
that store data permanently.
• Data are also stored in variables for example a=10 when
program executed then we can access it when program
execution is terminated the memory will destroy
• But when we store data in files it will store permanently
when execution terminated the memory will not destroy .
File handling
• File handling is a mechanism through which we can handle
( read, write, create append etc..) the file.
• Syntax :-- file_obj = open(‘file_path’, ‘Mode’)
Open ( ) is a function to work with files and it takes two
parameters.
File Mode File operations
• r = read create ( )
• w = write read ( )
• a = append write ( )
• r+ = read and write copy ( )
• b = binary mode delete ( )
How to create a File
How to write data in File
How to Append data in File
How to read data from File
Conti…
Conti…
Reading data From a File not Exist
Reading data From a File Exist
Copy data From one file to another File
How to delete a File