Python Binary Files Explained | Read, Write, Append & Update (All BasicOperations Covered)

Pubblicato il: 19 dicembre 2025
sul canale di: Krishnendu Bhattacharjee
39
1

#Python #BinaryFiles #PythonFileHandling #PickleModule #CBSEComputerScience #Class12Python #PythonTutorial
#FileHandlingInPython #LearnPython #ComputerScience
#PythonForStudents #CodingBasics

Binary files in Python can look scary, but they’re really just files that don’t store plain text. In this video, we cover all basic operations possible on Python binary files in a clear and structured way.

🔹 Topics covered in this video:
• How are binary files used in Python
• Opening binary files using rb, wb, ab
• Writing data to binary files using pickle
• Reading binary files using pickle.load()
• Appending records to a binary file
• Searching and updating records in a binary file
• Deletion of records in a binary file

This video is especially useful for the CBSE Class 12 Computer Science students, board preparation, and beginners learning Python file handling.

If binary files ever felt confusing, this video fixes that.

Code of the operations covered in the video is given below:
#binary file options
#add,view,search,delete,update records
#student: roll, name, marks

import pickle
def addrec():
a=int(input("Enter the roll : "))
b=input("Enter the name : ")
c=int(input("Enter the marks : "))
d=[a,b,c]
with open("stud.dat","ab") as f:
pickle.dump(d,f)

def viewrec():
with open("stud.dat","rb") as f:
try:
while True:
x=pickle.load(f)
print("Roll: ",x[0])
print("Name: ",x[1])
print("Marks: ",x[2])
except EOFError:
pass

def searchrec():
y=int(input("Enter the roll number to be searched: "))
with open("stud.dat","rb") as f:
try:
p=False
while True:
x=pickle.load(f)
if x[0]==y:
p=True
print("Roll: ",x[0])
print("Name: ",x[1])
print("Marks: ",x[2])
except EOFError:
if p==False:
print("Record not found")

def delrec():
y=int(input("Enter the roll number to be deleted: "))
with open("stud.dat","rb") as f:
try:
a=[]
p=False
while True:
x=pickle.load(f)
if x[0]!=y:
a.append(x)
else:
p=True
except EOFError:
pass
print(a)

with open("stud.dat","wb") as f:
for b in a:
pickle.dump(b,f)

if p==False:
print("Record not Found")
else:
print("Record Deleted")

def modrec():
y=int(input("Enter the roll number to be modified: "))
z=int(input("Enter the correct marks : "))
with open("stud.dat","rb") as f:
try:
a=[]
p=False
while True:
x=pickle.load(f)
if x[0]==y:
x[2]=z
else:
p=True
a.append(x)
except EOFError:
pass
with open("stud.dat","wb") as f:
for b in a:
pickle.dump(b,f)

if p==False:
print("Record not Found")
else:
print("Record Deleted")

def menu():
while True:
print("M A I N M E N U")
print("1. Add records")
print("2. View records")
print("3. Search records")
print("4. Delete records")
print("5. Update records")
print("6. Exit")
ch=int(input("Enter your choice (1-6): "))
if ch==1:
addrec()
elif ch==2:
viewrec()
elif ch==3:
searchrec()
elif ch==4:
delrec()
elif ch==5:
modrec()
elif ch==6:
print("Thanks for running the program")
break

menu()


In questa pagina del sito puoi guardare il video online Python Binary Files Explained | Read, Write, Append & Update (All BasicOperations Covered) della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Krishnendu Bhattacharjee 19 dicembre 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 39 volte e gli è piaciuto 1 spettatori. Buona visione!