Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Computer Science – File Handling – Binary Files

Rating
-
Sold
-
Pages
7
Grade
A+
Uploaded on
03-09-2024
Written in
2024/2025

Computer Science – File Handling – Binary Files – 7 Pages – Introduction, Pickling Python, Operations on Binary Files - Very Helpful for Students and Teachers

Institution
Course

Content preview

File Handling : Binary Files
Amit Singh
MGM Higher Secondary School BOKARO
INTRODUCTION
 Most of the files that we see in our computer system are called Binary files.




|| COMPUTER SCIENCE XII ||
 Example:


Executable
Image files Video files Audio files Archieve files
files
.png .mp4 .mp3 .zip .exe
.jpg .3gp .wav .rar
.dll
.gif .mkv .mka .iso
.bmp .avi .aac .7z .class

 We can open some binary files in the normal text editor but we can’t read the content
present inside the file.
 Because of binary format which is understandable by computer or a machine.
 There is no requirement of translator.
 Processing of these files are easy and fast.
 In Python, pickling process is used to read, write, append and update binary files.

PICKLING IN PYTHON
 Pickle is responsible for serializing and de-serializing of data.
 Serializing means converting a python object (like List, Dictionary etc.) into byte
stream and de-serializing means converting the stream back to python object.
 The advantage is that we can use store data in file for later use, send it over different
protocols, save the data in databases.
PICKLE MODULE
 pickle.dump()
 Used to write the object in a file
 Syntax: pickle.dump(<structure>,file object)
 Here, structure can be any sequence such as list, dictionary of Python.
 And file object is the file handle of the file, in which to write.
 pickle.load()
 Used to read the data from a file.
 Syntax: Structure=pickle.load(file object)
 Here, structure can be any sequence such as list, dictionary of Python.
 And file object is the file handle of the file, from which to read.
1 Page

, File Handling : Binary Files
Amit Singh
MGM Higher Secondary School BOKARO
OPERATIONS ON BINARY FILE




|| COMPUTER SCIENCE XII ||
###SIMPLE WRITE AND READ IN BINARY FORMAT ###
import pickle
def write():
f=open("Binaryfile.dat",'wb')
list=[1,2,3,4]
pickle.dump(list,f)
f.close()
def read():
f=open("Binaryfile.dat",'rb')
lst=pickle.load(f)
print(lst)
f.close()
write()
read()

###MULTIPLE RECORDS AT A SAME TIME BUT IN A SINGLE LIST
APPENDING DATA INTO THE FILE ###
import pickle
def write():
f=open("Binaryfile.dat",'wb')
Rec=[]
while True:
roll=int(input("ENTER ROLL NO.: "))
name=input("ENTER NAME OF STUDENT: ")
marks=int(input("ENTER THE TOTAL MARKS OBTAINED: "))
grade=input("ENTER THE GRADE: ")
R=[roll,name,marks,grade]
Rec.append(R)
ch=input("DO YOU WANT INSERT MORE ENTRIES (y/n): ")
if ch=='n' or ch=='N':
break
pickle.dump(Rec,f)
f.close()
def read():
f=open("Binaryfile.dat",'rb')
2




lst=pickle.load(f)
Page




print(lst)

Written for

Course

Document information

Uploaded on
September 3, 2024
Number of pages
7
Written in
2024/2025
Type
Exam (elaborations)
Contains
Only questions

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
kbzone

Also available in package deal

Get to know the seller

Seller avatar
kbzone ICSE
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
284
Last sold
-
Notes On All Subjects

A Store where Notes, Presentations, Questions &amp; Answers, Classnotes, Study mqaterials and Studyguides are available at a very nominal preice. The notes are very useful for both the Students and Teachers.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions