【问题标题】:Python updating a class attribute that is a list [closed]Python更新作为列表的类属性[关闭]
【发布时间】:2022-06-17 17:13:42
【问题描述】:

所以这里只需要一个小指针。 我有一个创建以下内容的类:

class EmployeeProfile:
def __init__(self, profile):
    self.displayname = profile.get('displayName')
    self.email = profile.get('email')
    self.firstname = profile.get('firstName')
    self.surname = profile.get('surname')
    self.fullname = profile.get('fullName')
    #
    self.costcode = profile.get('work').get('custom')\
        .get('Cost Category_t9HHc')
    self.title = profile.get('work').get('title')
    self.department = profile.get('work').get('department')
    self.city = profile.get('work').get('site')
    self.id = profile.get('work').get('employeeIdInCompany')
    #
    self.manageremail = ''
    self.costline = 'N/A'
    self.groups = {}
    self.attest = []

我希望能够更新/扩展 self.groups 和 self.attest,它们是字典和列表类型。我怎样才能打电话更新这些?

所以如果我创建一个名为 SP 的类实例:

SP = EmployeeProfile()

我通常会这样做:

SP.attrib = ?

难以理解我是如何引用该列表的。

【问题讨论】:

  • 是吗? SP.groups['key'] = 'value', SP.attest.append('value')…?!

标签: python class


猜你喜欢
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-26
  • 2021-11-01
相关资源
最近更新 更多