File Handling in Python - File Types: Text, Binary, CSV | Modes in File Handling r/w/a/+/b | 12 CS

Опубликовано: 22 Октябрь 2024
на канале: Aditya Aurange
22,771
329

In this tutorial we will learn File Handling in Python

Types of File :-
Text File - Stores data in ASCII, UNICODE Format
Binary File - Stores data as in the format of the memory
CSV File - Stores Tabular Data separated by comma ','

Modes in File Handling :-
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.

Opening file in python:-
open(path, mode) function opens the file with the specified path of file & opening mode

Closing file in python:-
close() function closes the file & pushes/makes all the changes in the file.