0% found this document useful (0 votes)
9 views4 pages

Binary Files

The document provides an overview of binary files, specifically focusing on the .dat extension and their characteristics, including the use of the Pickle module for serialization and deserialization of data. It explains functions for reading and writing binary files, such as load() and dump(), as well as file pointer manipulation methods like seek() and tell(). The document outlines the processes for insertion, searching, updating, and deletion of data in binary files.

Uploaded by

hana.ahinus.5217
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)
9 views4 pages

Binary Files

The document provides an overview of binary files, specifically focusing on the .dat extension and their characteristics, including the use of the Pickle module for serialization and deserialization of data. It explains functions for reading and writing binary files, such as load() and dump(), as well as file pointer manipulation methods like seek() and tell(). The document outlines the processes for insertion, searching, updating, and deletion of data in binary files.

Uploaded by

hana.ahinus.5217
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/ 4

BINARY FILES

INTRO:
 Extension= .dat
 Most of the computer files are of this format. Eg:.docx , .png , .mp3
 Encoded in binary format which is only understood by a computer or a
machine.
 Needn’t be translated as the computer can understand it as such.
 No delimiter to end a line

PICKLE:
 It is a module imported to read and write into a binary file.
 Used for:
o Pickling(serializing) = Process of conversion of data structures in
RAM into byte streams stored in databases.
o Unpickling(deserialIzing) =Processs of conversion of byte stream into
original data structures
 Pickling is required at the time of reading and writing in a binary file.
 Syntax:
import pickle
 Contains 2 functions:
 Load(): Used for reading contents from the files.
 Reads one value at a time,hence need to be called each
time dump is used
 Need to use loop.
 Reading mode =’rb’
Syntax:
object = load(fileobject)
variable= pickle.load(fileobject)
 dump(): Used for writing contents into the file.
 Dumps altogether at a time.
 Writing mode=’ wb’
Syntax:
Pickle.dump(object/sequence,fileobject)
INSERTION:
 Use dump().
SEARCH:
o Use load().

UPDATION:
o Use load().
DELETION:

SEEK():
o It is used to place the filepointer or cursor at a specified
position.
o Data will be read from this position onwards.
o Used in 2 ways:
 Absolute positioning: syntax is-
f.seek(position).The cursor will move that
many bytes from the beginning irrespective of
the current position of the cursor.
 Relative positioning:syntax is-
f.seek(offset,from_what).This will move the
cursor from the specified position according to
the offset/bytes specified[(+)-moves fwd,(-) -
moves bkd]
o from_what can take 3 values:
0= beginning of the file
1=current cursor position
2=end of the file
No arg=beginning
TELL():
o Gives the current position of the cursor.
o Syntax is
f.tell()
o If the file is opened in:
Reading/writing mode = cursor at the beginning
Appending mode= cursor at the end of the file

You might also like