jeudi 9 janvier 2020

python3: how to use for loop and if statements over class attributes?

I have the following class:

class equipment:
    def __init__(self, name, location, status):
        self.name = name
        self.location = location
        self.status=status 

class device(equipment):
    def __init__(self, name, location,status):
        super().__init__(name, location,status)


device1 = device("device1 ", (5, 2), 0)
device2 = device("device2", (10, 2), 0)
device3 = device("device3", (15, 3), 0)
device4 = device("device4", (5, 5), 0)

all_devices = ['device1', 'device2', 'device3', 'device4']

and based on another code: I get status_devices=[1,0,1,1] so I wanted to update the original status by using for loop and if statement(to print only the device that has status=1),

for n in range(0, 4):
    all_devices[n].status=status_devices[n]

this way gave me the error: str object has no attribute status

Thanks

Aucun commentaire:

Enregistrer un commentaire