-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle.py
67 lines (50 loc) · 1.53 KB
/
vehicle.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pickle
class Vehicle:
def __init__(self, VehicleID = "", Registration = "", DateOfRegistration = None, EngineSize = 0, PurchasePrice = 0.00):
self.VehicleID = VehicleID
self.Registration = Registration
self.DateOfRegistration = DateOfRegistration
self.EngineSize = EngineSize
self.PurchasePrice = PurchasePrice
def output(self):
print(f"VehicleID: {self.VehicleID}")
print(f"Registration: {self.Registration}")
print(f"DateOfRegistration: {self.DateOfRegistration}")
print(f"EngineSize: {self.EngineSize}")
print(f"PurchasePrice: {self.PurchasePrice}")
MyCar = Vehicle()
MyCar.VehicleID = "00100101"
MyCar.Registration = "PYT009"
MyCar.DateOfRegistration = "23/11/2023"
MyCar.EngineSize = 2500
MyCar.PurchasePrice = 21000.00
MyCar.output()
#####################
## Sequential File ##
#####################
Cars = [Vehicle() for i in range(100)]
CarFile = open("Cars.dat", "wb")
for item in range(100):
pickle.dump(Cars[item], CarFile)
CarFile.close()
CarFile = open("Cars.dat", "rb")
Car = []
for _ in range(100):
Car.append(pickle.load(CarFile))
CarFile.close()
#################
## Random File ##
#################
JoWee = Vehicle()
JoWee.VehicleID = "asdasdq"
CarFile = open("JoWee.dat", "wb")
Address = hash(JoWee.VehicleID)
CarFile.seek(Address)
pickle.dump(JoWee, CarFile)
CarFile.close()
CarFile = open("JoWee.dat", "rb")
Address = hash(JoWee.VehicleID)
CarFile.seek(Address)
JoWee = pickle.load(CarFile)
CarFile.close()
#3_november