gpt4 book ai didi

Python类属性报错AttributeError : can't set attribute

转载 作者:太空宇宙 更新时间:2023-11-04 08:43:55 51 4
gpt4 key购买 nike

class DockerEngine(Device):

def __init__(self):
super(DockerInfo, self).__init__()
self.docker_id = None
self.host_ip_address = None
self.total_containers = 0
self.running_containers = 0
self.paused_containers = 0
self.stopped_containers = 0

@property
def host_ip_address(self):
return self._host_ip_address

@host_ip_address.setter
def host_it_address(self, ip):
self._host_ip_address = ip

@property
def docker_id(self):
return self._docker_id

@docker_id.setter
def docker_id(self, id):
self._docker_id = id

当我初始化一个 DockerEngine 对象时,它提示说在 __init__ self.host_ip_address 中,无法设置属性。

最佳答案

你的代码有错字

host_it_address更改为host_ip_address.

@host_ip_address.setter
def host_it_address(self, ip): <--- WRONG FUNCTION NAME
self._host_ip_address = ip

关于Python类属性报错AttributeError : can't set attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42481008/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com