AttributeError: '...' object has no attribute '...'

AttributeError: '...' object has no attribute '...'

我希望能够做到,如果对人员问题的描述包括需要新密码,它将用新生成的密码替换 IT 支持响应(尚未创建 class 但就目前而言,我只想确定我可以打印它会做到这一点)。请暂时忽略自动分配 method/ticket 计数器内容。

对于 class callPassword,我不想在 newPassword 中插入任何数据,我只是希望它在问题描述中提到想要时将 ticketResponse 替换为“已生成新密码”更改密码。但是我不知道我在这里做错了什么,花了2天时间(非常初学者)

我不断收到:


t3P = callPassword()

self.tc = self.ticketCreation()

AttributeError: 'callPassword' object has no attribute 'ticketCreation'

代码:

class ticket(object):
    
    counter = 2000

    def __init__(self):
        self.name = 'Ticket'
        self.tc = self.ticketCreation()
        self.sr = self.supportResponse()
        self.pc = self.callPassword()

class ticketCreation(ticket):

    def __init__(self, creatorName, staffID, email, issueDescription):
        self.creatorName = creatorName
        self.staffID = staffID
        self.email = email
        self.issueDescription = issueDescription
        ticket.counter += 1
        self.ticketNumber = ticket.counter
        
    def displayTicket(self):
        ticket_info = []
        ticket_info.append(self.ticketNumber)
        ticket_info.append(self.creatorName)
        ticket_info.append(self.staffID)
        ticket_info.append(self.email)
        ticket_info.append(self.issueDescription)
            
        if self.creatorName == "":
            print("Ticket Creator: Not Specified")
        else:
            print("Ticket Creator: " + str(ticket_info[1]))
        if self.staffID == "":
            print("--STAFF ID REQUIRED TO SUBMIT TICKET--")
            return 
        else:
            print("Staff ID: " + str(ticket_info[2]))
        if self.email == "":
            print("Email Address: Not Specified")
        else: 
            print("Email Address: " + str(ticket_info[3]))
        if self.issueDescription == "":
            print("--DESCRIPTION OF YOUR ISSUE IS REQUIRED TO SUBMIT TICKET--")
            return 
        else:
            print("Description: " + str(ticket_info[4]))

    def autoAssign(self):
        if self.staffID == "" or self.issueDescription == "":
            print("TICKET NOT CREATED\nTicket Number: N/A")
            return
        else:
            print("Ticket Number: " + str(self.ticketNumber))

class supportResponse(ticket):
    def __init__(self, ticketResponse):
            self.ticketResponse = ticketResponse

    def respond(self):
        if self.ticketResponse == "":
            print("Response: Not Yet Provided")
        else:
            print("Response: " + self.ticketResponse)

    def resolve(self):
        if self.ticketResponse == "":
            print("Ticket Status: Open")
        else:
            print("Ticket Status: Closed")
        
    def reopenStatus(self):
        print("Ticket Status: Reopened")

class callPassword(ticket):
            
    def newPassword(self):
        if "change password" in ticketCreation.issueDescription:
            supportResponse.ticketResponse = "New password generated"
            print(supportResponse.ticketResponse)
     

t1 = ticketCreation("Inna", "INNAM", "inna@whitecliffe.co.nz", "My monitor stopped working")
t1R = supportResponse("sucks")
t2 = ticketCreation("", "MARIAH", "", "Request for video camera to conduct webinars")
t2R = supportResponse("")
t3 = ticketCreation("Joel", "JOELS", "", "change password")
t3P = callPassword()


print("\nPrinting Tickets:\n")

t1.autoAssign()
t1.displayTicket()
t1R.respond()
t1R.resolve()
print()

t2.autoAssign()
t2.displayTicket()
t2R.respond()
t2R.resolve()
print()

t3.autoAssign()
t3.displayTicket()
t3P.newPassword()
t3R.resolve()

ticket class 中,您正试图从不存在的方法中分配新的实例属性。

尝试从 ticket 构造函数的赋值中删除 self

像这样:

class ticket(object):
    
    counter = 2000

    def __init__(self):
        self.name = 'Ticket'
        self.tc = ticketCreation()  # ticketCreation constructor has parameters.
        self.sr = supportResponse() # supportResponse class does too
        self.pc = callPassword()