0% found this document useful (0 votes)
2 views2 pages

3.1 Introduction To Files

File handling in Python is crucial for web applications, allowing for the creation, reading, updating, and deletion of files. There are three main types of files: text, binary, and CSV, and file operations typically involve opening, reading or writing, and closing the file. The open() function is used to access files with various modes including read, append, write, and create, along with options for text or binary handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

3.1 Introduction To Files

File handling in Python is crucial for web applications, allowing for the creation, reading, updating, and deletion of files. There are three main types of files: text, binary, and CSV, and file operations typically involve opening, reading or writing, and closing the file. The open() function is used to access files with various modes including read, append, write, and create, along with options for text or binary handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

INTRODUCTION TO FILES

File handling is an important part of web application.

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.

Three types of Files.

⮚ Text File

⮚ Binary File

⮚ CSV (Comma Separated Values ) File

File operation can be done in the following order.

⮚ Open a file

⮚ Read or write - Performing operation

⮚ Close the file

OPENING A FILE

open() function that accepts two arguments, file name and access mode in which the file is accessed.

SYNTAX

file object = open(<file-name>, <access-mode>, <buffering>)

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

if the file should be handled as binary or text mode

"t" - Text - Default value. Text mode

"b" - Binary - Binary mode (e.g. images)

You might also like