-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBinary File Write.py
More file actions
33 lines (28 loc) · 967 Bytes
/
Binary File Write.py
File metadata and controls
33 lines (28 loc) · 967 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
31
32
33
import pickle
import datetime
class student:
def __init__(self):
self.name = ""
self.regNo = 0
self.dOB = datetime.datetime.now()
self.fullTime = True
def writeData():
thisRec = student()
studentFile = open('students.dat', 'w+b')
thisRec.name = input("Enter student name: ")
thisRec.regNo = int(input("Enter Registration No: "))
day = int(input("enter day for date of birth: "))
month = int(input("enter month "))
year = int(input("enter year: "))
thisRec.dOB = datetime.datetime(year, month, day)
thisRec.fullTime = bool(input("Full Time? [True/False]"))
pickle.dump(thisRec, studentFile)
studentFile.close()
def readData():
thisRec = student()
studentFile = open('students.dat', 'rb')
thisRec = pickle.load(studentFile)
print(thisRec.name, thisRec.regNo, thisRec.dOB.isoformat())
studentFile.close()
writeData()
readData()