




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this pptx, I had written brief notes of data file handling which is very helpful for students in class 10, 11, 12
Typology: Study notes
1 / 158
This page cannot be seen from the preview
Don't miss anything!





























































































Programming and Computational
Thinking (PCT-2)
(80 Theory + 70 Practical)
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
Prepared byPrepared by
Courtesy CBSE
After going through the chapter, student will
be able to:
Understand the importance of data file for
permanent storage of data.
Understand how standard Input/Output
function work.
Distinguish between text and binary file
Open and close a file ( text and binary)
Read and write data in file
Write programs that manipulate data file(s
A file (i.e. data file) is a named place on
the disk where a sequence of related data is
stored.
In python files are simply stream of
data, so the structure of data is not stored in
the file, along with data.
Basic operations performed on a data file are:
Contd.. next
What is Text File?
A text file is usually considered as sequence of
lines. Line is a sequence of characters (ASCII or
UNICODE), stored on permanent storage media.
The default character coding in python is ASCII each
line is terminated by a special character, known as
End of Line (EOL). At the lowest level, text file will
be collection of bytes. Text files are stored in
human readable form and they can also be created
using any text editor.
What is Binary File?
A binary file contains arbitrary binary data i.e.
numbers stored in the file, can be used for
numerical operation(s). So when we work on
binary file, we have to interpret the raw bit
pattern(s) read from the file into correct type of
data in our program. In the case of binary file it is
extremely important that we interpret the correct
data type while reading the file. Python provides
special module(s) for encoding and decoding of
data for binary file.
To handle data files in python, we need to
have a file object. Object can be created by
using open() function or file() function.
To work on file, first thing we do is open it.
This is done by using built in function open().
Syntax of open() function is
file_object = open(filename [, access_mode]
[,buffering])
open() requires three arguments to work,
first one ( filename ) is the name of the file on
secondary storage media, which can be string
constant or a variable. The name can include the
description of path, in case, the file does not
reside in the same folder / directory in which we
are working
The second parameter (access_mode)
describes how file will be used throughout the
program. This is an optional parameter and the
default access_mode is reading.
While writing the content in the file, first it
goes to buffer and once the buffer is full, data is
written to the file. Also when file is closed, any
unsaved data is transferred to file. flush()
function is used to force transfer of data from
buffer to file