-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.2.py
More file actions
30 lines (28 loc) · 809 Bytes
/
Copy path4.2.py
File metadata and controls
30 lines (28 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import pickle
class Student:
def __init__(self,name,rollno,marks):
self.name=name
self.rollno=rollno
self.marks=marks
def display(self):
print(self.name,"\t",self.rollno,"\t",self.marks)
with open("student.dat",'wb') as f:
n=int(input("How many students?"))
for i in range(n):
name=input("Enter name of student")
rollno=int(input("Enter rollno of student"))
marks=int(input("Enter marks of student"))
s=Student(name,rollno,marks)
#pickle operation
pickle.dump(s,f)
#Unpickle operation
f1=open('student.dat','rb')
print("Student Details:")
while True:
try:
obj = pickle.load(f1)
obj.display()
except EOFError:
print("All students details displayed.....")
break
f1.close()