Data file handling, Study notes of Computer science

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

2019/2020

Uploaded on 11/21/2020

sparsh-saxena-1
sparsh-saxena-1 🇮🇳

5

(1)

1 document

1 / 158

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHAPTER - V
DATA FILE HANDLING
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Data file handling and more Study notes Computer science in PDF only on Docsity!

CHAPTER - V

DATA FILE HANDLING

Unit I

Unit I

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

Praveen M Jigajinni

Prepared byPrepared by

Courtesy CBSE

Class XII

LEARNING OUTCOMESLEARNING OUTCOMES

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

INTRODUCTION – DATA FILESINTRODUCTION – DATA FILES

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:

1.^ 1. Naming a fileNaming a file

2.^ 2. Opening a fileOpening a file

3.^ 3. Reading data from the fileReading data from the file

4.^ 4. Writing data in the fileWriting data in the file

5.^ 5. Closing a fileClosing a file

BASIC OPERATIONS ON FILE^ BASIC OPERATIONS ON FILE

FILE PROCESSINGFILE PROCESSING

Contd.. next

INTRODUCTION – DATA FILESINTRODUCTION – DATA FILES

6.^ 6. CREATE A COPY OF FILECREATE A COPY OF FILE

7.^ 7. UPDATING DATA IN THE FILE … etcUPDATING DATA IN THE FILE … etc

5.^ 5. DELETING DATA FROM FILEDELETING DATA FROM FILE

TYPES OF FILESTYPES OF FILES

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.

1.^ 1. TEXT FILETEXT FILE

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.

2.^ 2. BINARY FILEBINARY FILE

OPENING AND CLOSING FILESOPENING AND CLOSING FILES

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])

OPENING AND CLOSING FILESOPENING AND CLOSING FILES

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.

OPENING AND CLOSING FILESOPENING AND CLOSING FILES

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

FILE ACCESS MODESFILE ACCESS MODES