0% found this document useful (0 votes)
8 views

Chapter 5 (File Handling)

Uploaded by

sharad9shashwat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Chapter 5 (File Handling)

Uploaded by

sharad9shashwat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

GD GOENKA INTERNATIONAL SCHOOL

NOIDA EXTENSION
CLASS 12
COMPUTER SCIENCE
CHAPTER 5. FILE HANDLING

• A file is a collection of characters in which we can perform read and


write functions. And also, we can save it in secondary storage.
Data File Operations:
• Following main operations can be done on files:
o Opening a file
o Performing operations
▪ Read
▪ Write etc
o Closing the file
Besides above operations there are some more operations can be done on
files:
o Creating of files
o Traversing of data
o Appending data into file
o Inserting data into file
o Deleting data from file
o Copying of file
o Updating data into file
File Types: Files are of two types:

• Text File: A text file is sequence of line and line is the sequence of
characters and this file is saved in a permanent storage device. In text
file, each line terminates with a special character which is EOL (End of
Line). These are in human readable form and these can be created using
any text editor.
• Binary File: Binary files are used to store binary data such as images,
videos, audio etc. Generally, numbers are stored in binary files. In binary
files, there is no delimiter to end a line. Since they are directly in the
form of binary hence there is no need to translate them. That’s why
these files are easy and fast in working.
Opening and closing a file:
• We need a file variable or file handle to work files in Python.
• This file object can be created by using open () function or file ()
function.
• Open () function created a file object, which is used later to access the
file using the functions related to file manipulation.
• Its syntax is: <file_object>= open (<file_name>, <access_mode>)
• File accessing modes:
o read (r): to read the file
o write (w): to write to the file
o append (a): to write at the end of file
Operations in Binary File:
• If we want to write structure such as list, dictionary, etc and also we
want to read it then we have to use a module in python known as pickle.
• Pickling means converting structure into byte stream before writing the
data into file.
• And when we read a file then a opposite operation is to be done means
unpickling.
• Pickle module has two methods: dump () to write and load () to
read
• For more coding questions, kindly go through the examples given in the
chapter.

You might also like