-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserializar_objetos.py
More file actions
39 lines (29 loc) · 905 Bytes
/
serializar_objetos.py
File metadata and controls
39 lines (29 loc) · 905 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
34
35
36
37
38
39
import pickle
class Vehiculos():
def __init__(self,marca,modelo):
self.marca=marca
self.modelo=modelo
self.enmarcha=False
self.acelera=False
self.frena=False
def arrancar(self):
self.enmarcha=True
def acelerar(self):
self.acelera=True
def frenar(self):
self.frena=True
def estado(self):
print(f"Marca: {self.marca} \nModelo: {self.modelo} \nEn marcha: {self.enmarcha} \nAcelerando: {self.acelera} \nFrenando: {self.frena}")
coche1=Vehiculos("Mazda","MX5")
coche2=Vehiculos("Seat","Leon")
coche3=Vehiculos("Renault","Megane")
coches=[coche1,coche2,coche3]
fichero=open("losCoches","wb")
pickle.dump(coches,fichero)
fichero.close()
del (fichero)
ficheroApertura=open("losCoches","rb")
misCoches=pickle.load(ficheroApertura)
ficheroApertura.close()
for c in misCoches:
print(c.estado())