0% found this document useful (0 votes)
38 views1 page

Binary files-I-Group O2

Binary files use extensions like .dat and .bin and the pickle module is used to write and read from them. The dump() method is used to convert Python objects to binary for writing and load() reads the binary data and returns an object.

Uploaded by

shahin appu
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)
38 views1 page

Binary files-I-Group O2

Binary files use extensions like .dat and .bin and the pickle module is used to write and read from them. The dump() method is used to convert Python objects to binary for writing and load() reads the binary data and returns an object.

Uploaded by

shahin appu
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/ 1

Binary files-

Main points

 Binary files having extension- .dat , .bin


 Module used for binary files - pickle

Syntax - import pickle

 Method to write/read in binary file- dump()/load()

o dump()- This method is used to convert (pickling) Python objects for writing data in a
binary file.

Syntax of dump() is as follows:

dump(data_object, file_object)
e.g pickle.dump(L,f1)
e.g
import pickle
L=[1,"Geetika",'F', 26]
f1=open("mybinary.dat", "wb")
pickle.dump(L,f1)
fileobject.close()
 load()-This method is used to load (unpickling) data from a binary file.

Syntax of load() is as follows:

Store_object = load(file_object)

e.g. a= pickle.load(f1)

e.g import pickle


f1=open("mybinary.dat","rb")
a=pickle.load(f1)
f1.close()
print(data)

You might also like