【发布时间】:2020-01-09 22:04:20
【问题描述】:
我有以下课程:
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']
并基于另一个代码:我得到 status_devices=[1,0,1,1] 所以我想通过使用 for 循环和 if 语句来更新原始状态(只打印状态=1的设备),
for n in range(0, 4):
all_devices[n].status=status_devices[n]
这种方式给了我错误:str object has no attribute status
谢谢
【问题讨论】:
标签: python python-3.x if-statement