Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python class property error AttributeError: can't set attribute

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

When I initialize a DockerEngine object, it complains that in __init__ self.host_ip_address, can't set attribute.

like image 809
typing... Avatar asked Feb 06 '23 00:02

typing...


1 Answers

Your code has a typo

Change host_it_address to host_ip_address.

@host_ip_address.setter
def host_it_address(self, ip): <--- WRONG FUNCTION NAME
    self._host_ip_address = ip
like image 116
shx2 Avatar answered Feb 08 '23 14:02

shx2