'In python, how to call a variable to create a method, without defining it in an __init__?
I need to write a method that will call on another class (once I have created it) to create a password. I need to be able to use the variable issueDescription from ticketCreation class to change what the output of respond() will be from supportResponse class. Basically, if the tickets issue is that they need a new password, I want the support response to respond with that new password (for now, I'm just trying to get it to return a string). I'm trying to do this under newPassword, however to be able to call on the ticketCreation.issueDescription within the supportResponse class, I seemingly need to put ticketCreation in the parameters for supportresponse __init__, but then that means I need to manually input that positional argument into respond(), which defeats the point of it being automatically triggered if the words "change password" is in the issueDescription (this being the output in case I'm not explaining this very well:
t1R = supportResponse("sucks")
TypeError: __init__() missing 1 required positional argument: 'ticketCreation'
Feel like I might be overthinking this, but here's what I've got:
class ticket(object):
counter = 2000
def __init__(self):
self.name = 'Ticket'
self.tc = ticketCreation(self.creatorName, self.staffID, self.email, self.issueDescription)
self.sr = supportResponse(self.ticketResponse)
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, ticketCreation):
self.ticketResponse = ticketResponse
self.problem = ticketCreation.issueDescription
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")
def newPassword(self):
if "change password" in self.problem:
self.ticketResponse = "New password generated: " #this will later call class passwordGenerator once I have made it
print(self.ticketResponse)
t1 = ticketCreation("Inna", "INNAM", "[email protected]", "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 = supportResponse.newPassword("")
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()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
