首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问python中的类成员数组

如何访问python中的类成员数组
EN

Stack Overflow用户
提问于 2020-08-17 19:28:31
回答 1查看 83关注 0票数 0

我有个班级成员。如何访问遥感器温度的“值”?这是生态蜜蜂调温模块的响应。

我尝试了thermostat_response.thermostatList,但是它给了我错误"AttributeError:'EcobeeThermostatResponse‘对象没有属性'thermostatList'“

我可以访问thermostat_response.pagethermostat_response.status,但不能访问thermostat_response.thermostatList

代码语言:javascript
复制
thermostat_response = EcobeeThermostatResponse(
  page=Page(
    page=1,
    pageSize=1,
    total=1,
    totalPages=1
  ),
  status=Status(
    code=0,
    message=
  ),
  thermostatList=[
    Thermostat(
      alerts=None,
      modelNumber=athenaSmart,
      reminders=None,
      remoteSensors=[
        RemoteSensor(
          capability=[
            RemoteSensorCapability(
              id=1,
              type=temperature,
              value=717
            ),
            RemoteSensorCapability(
              id=2,
              type=occupancy,
              value=true
            )
          ],
          code=EDGJ,
          id=rs:100,
          inUse=False,
          name=Bedroom,
          type=ecobee3_remote_sensor
        ),
        RemoteSensor(
          capability=[
            RemoteSensorCapability(
              id=1,
              type=temperature,
              value=696
            ),
            RemoteSensorCapability(
              id=2,
              type=humidity,
              value=62
            ),
            RemoteSensorCapability(
              id=3,
              type=occupancy,
              value=true
            )
          ],
          code=None,
          id=ei:0,
          inUse=True,
          name=Living Room,
          type=thermostat
        )
      ],
      runtime=None,
      weather=None
    )
  ]
)

这是EcobeeThermostatResponse类的定义

代码语言:javascript
复制
class EcobeeThermostatResponse(EcobeeStatusResponse):
    __slots__ = ['_page', '_thermostat_list']

    attribute_name_map = {'page': 'page', 'thermostat_list': 'thermostatList',
                          'thermostatList': 'thermostat_list', 'status': 'status'}

    attribute_type_map = {'page': 'Page', 'thermostat_list': 'List[Thermostat]', 'status': 'Status'}

    def __init__(self, page, thermostat_list, status):
        """
        Construct a EcobeeThermostatResponse instance

        :param page: The page information for the response
        :param thermostat_list: The list of thermostats returned by the request
        :param status: The api response code
        """
        self._page = page
        self._thermostat_list = thermostat_list
        EcobeeStatusResponse.__init__(self, status)

    @property
    def page(self):
        """
        Gets the page attribute of this EcobeeThermostatResponse instance.

        :return: The value of the page attribute of this EcobeeThermostatResponse instance.
        :rtype: Page
        """
        return self._page

    @property
    def thermostat_list(self):
        """
        Gets the thermostat_list attribute of this EcobeeThermostatResponse instance.

        :return: The value of the thermostat_list attribute of this EcobeeThermostatResponse instance.
        :rtype: List[Thermostat]
        """
        return self._thermostat_list
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-17 19:42:35

根据文档,您可以使用thermostat_response.thermostat_list() (作为函数)。

如果你没有文档怎么办?

如果遇到类似的问题,并且没有文档,可以使用Python的dir()输出对象的所有属性,例如:

代码语言:javascript
复制
`dir(thermostat_response)`

更多有关这方面的信息,在这个问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63457414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档